0

Main task is POST-autorization via Delphi program. Using the REST Client I found that, having url of site and two headers: *login_email* and *login_pass* I can successfully get the HTML codу and my POST auth form is OK, I'm logged in.

However, I wrote this Delphi code:

DataToSend := TStringList.Create;
DataToSend.Add('');

IdHTTP1.Request.ContentType := 'application/x-www-form-urlencoded';
IdHTTP1.Request.CustomHeaders.AddValue('login_email','some_email');
IdHTTP1.Request.CustomHeaders.AddValue('login_pass','some_password');

Memo1.Lines.Add(idHTTP1.Post('http://url.com', DataToSend));

My custom headers are not URL encoded.

I see the request headers:

Server: nginx/1.0.8
Date: Sun, 01 Sep 2013 17:03:59 GMT
Content-Type: text/html; charset=windows-1251
Connection: close
X-Powered-By: PHP/5.2.6-1+lenny16
Vary: Accept-Encoding

but ontained HTML is same page, for which POST-request has been sent with unprocessed form.

What am I doing wrong ?

Eugene Shmorgun
  • 2,083
  • 12
  • 42
  • 67
  • Some servers rejects the requests due to the default `User-Agent` set by Indy. If that's your case, you may try to fill the `IdHTTP1.Request.UserAgent` property with one of the favorite browsers to fake the server that you are browser. But it's just my guess (and quite a frequent problem). – TLama Sep 01 '13 at 17:22
  • I've added this Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.62 Safari/537.36 as UserAgent, but nothing's changed. – Eugene Shmorgun Sep 01 '13 at 17:40

1 Answers1

4

The POST request parameters never includes in HTTP header. Try that:

DataToSend := TStringList.Create;
DataToSend.Add('login_email=some_email');
DataToSend.Add('login_pass=some_password');
IdHTTP1.Request.ContentType := 'application/x-www-form-urlencoded';

Memo1.Lines.Add(idHTTP1.Post('http://url.com', DataToSend));
Alexandr
  • 338
  • 1
  • 4
  • 16