i build proxy server and it works great, however there are some sites which he cannot handle.
I tried to reduce the problem to its core and this is what i came up with:
My test case is: http://bits.wikimedia.org/en.wikipedia.org/load.php
which is one of the http messages transfered in each wikipedia page.
So i tried to build a request for it and send it via a socket like this:
String request1 =
"GET http://bits.wikimedia.org/en.wikipedia.org/load.php HTTP/1.1" +
"\r\n" +
"Host: bits.wikimedia.org" + "\r\n" +
"User-Agent: MyHttpProxy/example.java (http://stackoverflow.com/q/5924490/319266)" +
"\r\n" + "\r\n";
However i got 404 return code - which was strange because this page does exist!
I made alot of trys and made a new request which was different only in the request line:
String request2 =
"GET /en.wikipedia.org/load.php HTTP/1.1" +
"\r\n" +
"Host: bits.wikimedia.org" +
"\r\n" +
"User-Agent: MyHttpProxy/example.java (http://stackoverflow.com/q/5924490/319266)" +
"\r\n" + "\r\n";
and it worked! a good 200 was brought back with
some unimportent content("/* No modules requested. Max made me put this here */")
Can anyone tell me what is the problem here?
i looked at the rfc and i couldnt make any reason of this...
Here is the source code for running this test and print the resuls:
You would provide the full URL in the request line only if you're going via a proxy server. Direct requests to a web server need to follow the form as in request2 in your example.
Looking at the source, you send requests to port 80, which almost 100% means they're not going through a proxy. My guess is that you need to send request1 to port 8080 or whatever port your proxy is listening on.
As for the RFC, take a look at section 5.1.2. Note that the absolute path is used with proxies, and relative path with origin servers.
Related
I'm trying to fetch a subdirectory using a get request.
What I've tried (for mysite.com/search):
char message[] = "GET / \r\nHost:mysite.com/search\r\n\n\n";
This however is giving me a 400 error (bad request)
How do I correctly request a subdirectory?
Host only accepts the base url/ip. See that / right after the GET? That's where you request any subdirectories/files you want. The / you have there now indicates that you want the top level dictionary.
What you are looking for is:
char message[] = "GET /search \r\nHost:mysite.com\r\n\n\n";
I want to test proxy server. In order to make https request, browser sends CONNECT method beforehand (e.g. like Firefox does, when proxy is specified).
I can not achieve/send the same result in curl:
Following has root slash /www.example.com:443:
curl -X CONNECT http://proxy_host:proxy_port/www.example.com:443
Following will not work (without slash):
curl -X CONNECT http://proxy_host:proxy_portwww.example.com:443
Following is not what I want:
curl -X CONNECT http://proxy_host:proxy_port/some_path
So the first line of HTTP data should be CONNECT www.example.com:443 HTTP/1.1 but not CONNECT /www.example.com:443 HTTP/1.1 like curl sends in this case.
Maybe this question also related some-how, if I would know how to not send path.
NOTE! I do not want to use curl -x http://proxy_host:proxy_port https://www.example.com, because this option/flag -x does not work with custom SSL certificates --cacert ... --key ... --cert ....
Any ideas how to send plain header data or not specify path, or specify host and port as a path?
(-X simply replaces the string in the request so of course setting it to CONNECT will not issue a proper CONNECT request and will certainly not make curl handle it correctly.)
curl will do a CONNECT by itself when connecting to a TLS server through a HTTP proxy, and even though you claim -x breaks the certificate options that is an incorrect statement. The --cacert and other options work the same even when the connection is done through a HTTP proxy.
You can also make curl do a CONNECT trough a HTTP(S) proxy for other protocols by using -p, --proxytunnel - also in combination with -x.
What is minimal HTTP 200 OK Connection close response for Nginx/lua/openresty. I have:
local sock, err = ngx.req.socket(true)
sock:send("HTTP/1.1 200 OK\\r\\nConnection: close\\r\\n\\r\\n")
and curl says:
curl: (52) Empty reply from server
In a case of no response body, you should probably use 204 No Content response code; "201 Created" may be an option as well for requests that create resources.
Also: replace each double slash with a single one, as you don't need to escape slash to generate CR LF sequence.
I'm trying to make a get request from Arduino to GAE using PHP.
Arduino code:
#define DST_IP "https://myservice-183310.appspot.com" // my gae address
String cmd;
Wifi.println("AT+CIPMUX=0");
cmd = "AT+CIPSTART=\"TCP\",\"";
cmd += DST_IP;
cmd += "\",80\r\n";
Wifi.println(cmd);
if(Wifi.find("OK")){
Serial.println("LINK SUCCESS");
}
else{
Serial.println("LINK ERROR");
}
String user_info="GET /register.php?nfc_id=";
user_info+=nfc_id;
user_info+="\r\nHTTP/1.0 HOST: ";
user_info+=DST_IP;
user_info+="\r\n\r\n";
cmd="AT+CIPSEND=";
cmd+=String(user_info.length());
Wifi.println(cmd);
Wifi.print(user_info);
app.yaml in GAE:
runtime: php55
api_version: 1
handlers:
- url: /register.php
script: register.php
And I get a 404 error message, but "https://myservice-183310.appspot.com/register.php?nfc_id=ooo" works in the browser.
Why do I get this error and how can I fix it?
A valid HTTP request should look like:
GET /request.php?nfc_id=MY_NFC_ID HTTP/1.0
Host: myservice-183310.appspot.com
I'm no Arduino coder, but it looks like the request you are sending is:
GET /register.php?nfc_id=MY_NFC_ID
HTTP/1.0 HOST: https://myservice-183310.appspot.com
Things to note
The HTTP/1.0 goes on the same line as the GET, not on its own line.
The Host: HTTP header should not have the protocol https. SSL or non-SSL will already have been handled before these headers can be read, so they are unneeded (and so might only cause trouble).
I think the issue is the "HTTPS" protocol, try with "HTTP".
I've just started working with the Quectel MC60 and I am having some issues:
About HTTP GET method, I make the following commands:
AT+QIFGCNT=0
AT+QICSGP=1,"my_apn"
AT+QIREGAPP
AT+QIACT
AT+QSSLCFG="https",1
AT+QHTTPURL=39,40
my_url_39_bytes_long
AT+QHTTPGET=60
AT+QHTTPREAD=30
AT+QIDEACT
When using the QCOM software, I make a script running all the above commands sequentially. When it comes to the AT+QHTTPREAD command, the response is always "+CME ERROR: 3822" (HTTP response failed). What can it be? I'm sure the HTTP server is working properly.
The answer is that it is necessary to configure the request header
AT+QIFGCNT=0
AT+QICSGP=1,"my_apn"
AT+QIREGAPP
AT+QIACT
AT+QHTTPURL=39,40
my_url_39_bytes_long
AT+QHTTPCFG="requestheader",1
AT+QHTTPPOST=77
GET path HTTP/1.1
User-Agent: Fiddler
Host: www.my_host.com
AT+QHTTPREAD=30
AT+QIDEACT
NOTE: in AT+HTTPPOST=77, 77 is the size of the POST message (last two \r\n are required and count)
NOTE2: after GET you're supposed to write the path to the url inserted in AT+QHTTPURL. For example, if you specified your URL as https://www.my_host.com/debug/main/port, your AT+HTTPPOST request should look like this (don't forget the last two \r\n):
GET /debug/main/port HTTP/1.1
User-Agent: Fiddler
Host: www.my_host.com