Thread: No response from Google

  1. #1
    C++ Enthusiast jmd15's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    532

    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.
    Trinity: "Neo... nobody has ever done this before."
    Neo: "That's why it's going to work."
    c9915ec6c1f3b876ddf38514adbb94f0

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    491
    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.

  3. #3
    C++ Enthusiast jmd15's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    532
    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.
    Trinity: "Neo... nobody has ever done this before."
    Neo: "That's why it's going to work."
    c9915ec6c1f3b876ddf38514adbb94f0

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Sorting out cause of wrong response from class members
    By imCrushedByCode in forum C++ Programming
    Replies: 11
    Last Post: 04-18-2006, 12:30 AM
  2. RicBot Base and RicBot Google.
    By John_ in forum C++ Programming
    Replies: 3
    Last Post: 02-07-2006, 01:16 PM
  3. Firefox and Google Search
    By DeepFyre in forum Tech Board
    Replies: 0
    Last Post: 01-16-2005, 10:28 AM
  4. Array, reading in response etc...
    By mattz in forum C Programming
    Replies: 4
    Last Post: 12-05-2001, 11:41 AM