-
No response from Google
I am making a program that uses winsock, it will be doing different things and one is getting webpages. Anyways I made it to connect to google to test it out and it sends the request for index.html but doesn't receive a response. I'm thinking it's something to do with returning the request. Like if you telnet to google's port 80 and type in "GET /index.html HTTP/1.1" you have to hit Enter/Return twice to send the request. This is how I made and sent my request to google:
Code:
char request[256];
ZeroMemory(request,256);
strcpy(request,"GET /index.html HTTP/1.1");
request[253]='\r';
request[254]='\r';
request[255]='\0';
nret=send(siteSock,request,strlen(request),0);
I add the two '\r' to simulate the hitting enter twice like you have to in telnet. This doesn't invoke any response from google, and it should. I even tried it without the two carriage return characters('\r'). The request is successfully sent and everything, I don't think the lack of response has anything to do with my way of receiving it but I will post it anyways.
Code:
char buf[500];
ZeroMemory(buf,500);
nret=recv(siteSock,buf,500,0);
Any suggestions on why google doesn't respond? Thanks again.
-
Your logic is bjorked. settign 253-255 to \r\r\0 does nt affect the string since it ended awhile ago. So you have created:
"GET /index.html HTTP/1.1\0\0\0\0\0........\r\r\0"
Obviously this is not a valid request. strlen(request) gives you the lengthupto the first '\0'.
Secondly, HTTP takes \r\n as a new line, not \r\r. Read the HTTP RFC. Also, since the HTTP protocol takes two new lines, \r\n i sonly 1 new line by the specs stnadard so you need two of them.
Finally, why do you set the \r\r\0 with =? why not just do it in the strcpy? strcpy(..., "yadda\r\r");
Read the HTTP RFC.
-
Ok thanks this is what works:
Code:
char buffer[256];
ZeroMemory(buffer,256);
strcpy(buffer,"GET /index.html HTTP/1.1 \r\n\r\n\0");
nret=send(siteSock,buffer,strlen(buffer),0);
Now it returns it's index web page.