Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

400 Bad Request through Proxy


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 Endemoniada   Members   -  Reputation: 174

Like
0Likes
Like

Posted 18 May 2012 - 05:59 PM

Hi guys, I keep getting 400 Bad Request when I try the following:

char* proxy="xxx.xxx.xxx.xxx"; // I use the real number
char* port="8080";

SOCKET hSocket=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);

sockaddr_in sockAddr;
sockAddr.sin_family=AF_INET;
sockAddr.sin_port=htons(atoi(port));
sockAddr.sin_addr.S_un.S_addr=inet_addr(proxy);

connect(hSocket,(sockaddr*)(&sockAddr),sizeof(sockAddr));

char* request="GET http://www.useractive.net/proxy/azenv.php HTTP/1.1\r\n\r\n";

send(hSocket,request,strlen(request),0);

do{
 recv(hSocket,buffer,bufferlen,0);
 ...
}while(...);

I check for errors (which I omitted here) and all is well. Maybe you can spot something ?

Thanks

Sponsor:

#2 ApochPiQ   Moderators   -  Reputation: 7802

Like
0Likes
Like

Posted 18 May 2012 - 06:20 PM

The Host header is mandatory in HTTP 1.1. You should include it in your request to the proxy.

#3 Endemoniada   Members   -  Reputation: 174

Like
0Likes
Like

Posted 18 May 2012 - 08:10 PM

Thanks a lot for that info. I am still getting 400 errors though.

I am pretty sure I have to put the absolute URI in the initial request line, maybe I'm wrong ? I also don't know what to use for the Host, my understanding is that it gets ignored so it shouldn't matter but maybe I'm misunderstanding that.

Here is what I'm sending to the proxy:

GET hxxp://www.useractive.net/proxy/azenv.php HTTP/1.1
Host: /proxy/azenv.php

I tried a lot of different things for Host to no avail.

Please help. Thanks.

PS - the hxxp is really http

#4 hplus0603   Moderators   -  Reputation: 3297

Like
0Likes
Like

Posted 19 May 2012 - 12:26 AM

Your HTTP request is not correct.

Assuming you're talking directly to a web server, typically on port 80:
The GET URI part should contain only the "path and query" part of the URL. In your case, /proxy/azenv.php
The Host: header should contain only the FQDN of the host. In your case, www.useractive.net
The scheme (http://) is not part of the request at all, but the protocol (HTTP/1.1) that the scheme maps to is at the end of the GET line, like you have it.

If you're talking to a proxy, typically on address 3128, you generally do the same thing, unless you want to create a persistent connection (perhaps for encrypted HTTPS usage) in which case you can use the CONNECT method.

The full description of the HTTP protocol is available in RFC 2068. I highly recommend reading it: http://www.ietf.org/rfc/rfc2068.txt
Also, here is some code that implements a simple, working HTTP client in C/C++ code: http://www.enchantedage.com/http-get
And libcurl is a pretty good library for doing a very large part of the protocol quite correctly: http://curl.haxx.se/download.html

Edited by hplus0603, 19 May 2012 - 12:28 AM.

enum Bool { True, False, FileNotFound };




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS