Board index » delphi » Post doesn't work with Indy, works with ICS

Post doesn't work with Indy, works with ICS

Newbie to Winsock
Delphi5
Win98SE
Indy 8.x

Using Indy httpclient.exe
Get work fine but when trying to post to
URL = http://www.myip.org/cgi-bin/Login.py
post information = id=notmyrealid&pwd=notmyrealpw&Login=Login

The response is the enty form, ie the post wasn't accepted.

Using ICS Httptst.exe
with copy and paste of the same data as above,
post works fine, ie the response is the next form in the sequence.

Any ideas?

Thank you in advance.

Rob

Why don't you ever see the headline "Psychic Wins Lottery"?

 

Re:Post doesn't work with Indy, works with ICS


Hello

procedure Post(URL: string; const Source: TStrings;
         const AResponseContent: TStream); overload;
procedure Post(URL: string; const Source: TStream;
         const AResponseContent: TStream); overload;

HTTP.Post(URL, memoPostData1.Lines, ssResult);

I was having some problems with post just a couple of
days ago, and I found that the problem had something
to do with the Source param in the post method call.  
I was getting the string list from a memo component
that was on a different page that had not been displayed
yet.  

In other words, I had a form with a page control and
multiple pages on one of the pages was the "Post
Source Memo".  If the user had not gone to that page,
then for some (I don't know) reason the post failed.  
I assume it has something to do with the memo not
creating the string list if it is empty and not displayed
or something.

I fixed my problem by switching to "GET" but you may
not be able to.  Anyway, I thought this insight might lead
to a solution for you and inform the INDY authors of a
possible problem they should look into.

Good Luck
Michael L. Horne

On Sun, 1 Jul 2001 10:45:24 -0700, bgood

Quote
<nospam_rclaib...@hotmail.com> wrote:
>Newbie to Winsock
>Delphi5
>Win98SE
>Indy 8.x

>Using Indy httpclient.exe
>Get work fine but when trying to post to
>URL = http://www.myip.org/cgi-bin/Login.py
>post information = id=notmyrealid&pwd=notmyrealpw&Login=Login

>The response is the enty form, ie the post wasn't accepted.

>Using ICS Httptst.exe
>with copy and paste of the same data as above,
>post works fine, ie the response is the next form in the sequence.

>Any ideas?

>Thank you in advance.

>Rob

>Why don't you ever see the headline "Psychic Wins Lottery"?

Re:Post doesn't work with Indy, works with ICS


This is a small example of using post to send data to web server.

There is two different ways to do this operation.

Example 1:
<----------------------------------------------------------------->
procedure TForm1.SendPostData;
Const
  CRLF = #13#10;
Var
  aStream: TMemoryStream;
  Params: TMemoryStream;
  S: String;
begin
  aStream := TMemoryStream.create;
  Params := TMemoryStream.Create;

  HTTP.Request.ContentType := 'multipart/form-data;
boundary=-----------------------------7cf87224d2020a';

  try
    S := '-----------------------------7cf87224d2020a' + CRLF +
      'Content-Disposition: form-data; name="sys_return_url1"' + CRLF + CRLF
+
    'hello1' + CRLF +
    '-----------------------------7cf87224d2020a' + CRLF +
      'Content-Disposition: form-data; name="sys_return_url2"' + CRLF + CRLF
+
    'hello2' + CRLF +
    '-----------------------------7cf87224d2020a--';

    Params.Write(S[1], Length(S));

    with HTTP do begin
      try
        HTTP.Post('http://www.mydomain.com/postexampe.cgi', Params,
aStream);
      except
        on E: Exception do
          showmessage('Error encountered during POST: ' + E.Message);
      end;
    end;
  aStream.WriteBuffer(#0' ', 1);
  showmessage(PChar(aStream.Memory));
  except
  end;
end;
<----------------------------------------------------------------->

Example 2:
<----------------------------------------------------------------->
procedure TForm1.SendPostData;
Var
  aStream: TMemoryStream;
  Params: TStringStream;
begin
  aStream := TMemoryStream.create;
  Params := TStringStream.create('');
  HTTP.Request.ContentType := 'application/x-www-form-urlencoded';

  try
    Params.WriteString(URLEncode('sys_return_url=' + 'helo1' + '&'));
    Params.WriteString(URLEncode('sys_return_url=' + 'helo2'));
    with HTTP do begin
      try
        HTTP.Post('http://www.mydomain.com/postexampe.cgi', Params,
aStream);
      except
        on E: Exception do
          showmessage('Error encountered during POST: ' + E.Message);
      end;
    end;
  aStream.WriteBuffer(#0' ', 1);
  showmessage(PChar(aStream.Memory));
  except
  end;
end;
<----------------------------------------------------------------->

As you can see there is a difference in the way post stream is constructed
and the ContentType. In the first example ContentType is
"multipart/form-data; boundary=-----------------------------7cf87224d2020a"
and this boundary is used to separate different parameters.

In the second example the ContentType is
"application/x-www-form-urlencoded".
In this case the paremeteras are passed in the form

ParamName=ParamValue&ParamName=ParamValue

Note that the Pramaeters in the second form must be URL encoded.

Where these two formats of post information are used?

The first one is used when you have binary data to post and the second one
is when you are going to post only text fields.

--
Doychin Bondzhev
doyc...@dsoft-bg.com
DdSoft-Bulgaria
http://www.dsoft-bg.com

Quote
"bgood" <nospam_rclaib...@hotmail.com> wrote in message

news:MPG.15a901934ca1cb579896e3@forums.inprise.com...
Quote
> Newbie to Winsock
> Delphi5
> Win98SE
> Indy 8.x

> Using Indy httpclient.exe
> Get work fine but when trying to post to
> URL = http://www.myip.org/cgi-bin/Login.py
> post information = id=notmyrealid&pwd=notmyrealpw&Login=Login

> The response is the enty form, ie the post wasn't accepted.

> Using ICS Httptst.exe
> with copy and paste of the same data as above,
> post works fine, ie the response is the next form in the sequence.

> Any ideas?

> Thank you in advance.

> Rob

> Why don't you ever see the headline "Psychic Wins Lottery"?

Other Threads