Forum > Networking and Web Programming
[SOLVED] Synapse - 400 Bad Request
szocsmarci:
I want to get html from a page with Synapse. It works fine with many pages, but somewhere it doesn't.
It says:
HTTP/1.1 400 Bad Request
Date: Thu, 07 Apr 2011 19:57:37 GMT
Server: Apache
Content-Length: 344
Connection: close
Content-Type: text/html; charset=iso-8859-1
Your browser sent a request that this server could not understand.
Here is the code (Button1, Edit1, Memo1 on the form):
--- Code: ---procedure TForm1.Button1Click(Sender: TObject);
var
HTTP: THTTPSend;
l: tstringlist;
begin
HTTP := THTTPSend.Create;
l := TStringList.create;
try
if not HTTP.HTTPMethod('GET', edit1.Text) then
begin
ShowMessage('ERROR' + sLineBreak + IntToStr(Http.Resultcode));
end
else
begin
memo1.Lines.Clear;
memo1.Lines.Append(inttostr(Http.Resultcode) + ' ' + Http.Resultstring);
memo1.Lines.Append(Http.headers.text);
l.loadfromstream(Http.Document);
memo1.Lines.Append(l.text);
end;
finally
HTTP.Free;
l.free;
end;
end;
--- End code ---
But it is the same with synapse HttpGetText and lnet too.
I think I use wrong function (HTTP instead of HTTPs or something else)
Dibo:
If your interner browser shows page with http/https then this components should too. This is all code?
- Maybe server do some redirection. Synapse have property "AllowRedirection" or something like that. Check if this is TRUE
- I notify that some servers are sensitive for line breaks. I have similar problems with some servers when I separate headers line using unix #10. Try with #13#10
- Synapse default add some standards headers (like content-type, length etc) but lNET add only "host". Maybe server get headers which he doesn't understand or get not enough headers (LNet).
The best solution is run some sniffer (I use wireshark on linux) and look what send synapse/lNet and what internet browser and try send this same headers (in lNet you do this by LHTTPClient.AddExtraHeaders('Content-type: text/html; charset=iso-8859-1'))
Regards
ik:
Bad request usually means that the content of what you sent was not what the HTTP server/cgi expected.
All the 4xx errors are based on problems by the client side (wrong page, forbidden, etc...)
It can be not the whole header, wrong header (what is the content of Edit1.text that you are using ?)
If you can provide us the whole header (you can remove the IP/dns), it can be more helpful to understand what might have gone wrong in your request.
You can do it by using tools such as Wireshark.
--- Quote from: dibo ---- Maybe server do some redirection.
--- End quote ---
Redirect is a 3xx based "error" code. It can have code of "Moved Permanently", and it can have "Temporary Redirect".
Almindor:
This can happen if you go to a https page without the SSL.
Try lNEt with SSL turned on (use https).
szocsmarci:
--- Quote ---This can happen if you go to a https page without the SSL.
--- End quote ---
I turned on the SSL, but nothing hapenned. (lNET - SSL - properties)
I examined the traffic with Wireshark. It occured to me that Firefox sended cookies, while synapse didn't. But when I turned off the cookies in FF it worked. So it doesn't depends on cookies (I think).
I tried to extract the sended objects.
Synapse - doesn't work
GET /akt.php HTTP/1.1
FF - works
GET /akt.php HTTP/1.1
Host: www.here_comes_the_web_address.hu
User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:2.0) Gecko/20100101 Firefox/4.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: hu-hu,hu;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Accept-Charset: ISO-8859-2,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive
Cache-Control: max-age=0
And one more thing. When I type the IP number ((http://123.45.67.8/ instead of the name) in FF, I get the same error.
Navigation
[0] Message Index
[#] Next page