socket http

This is a discussion on socket http within the C++ Programming forums, part of the General Programming Boards category; Good afternoon people. Im currently working on very simple web-browser. After I connect to a webserver I send a command ...

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    291

    socket http

    Good afternoon people.

    Im currently working on very simple web-browser. After I connect to a webserver I send a command requesting a html-file, this looks like this : 'GET /filename HTTP 1.1 \r\n\r\n". The problem is that this command only works on some webserver and on others I get error 400 Bad request in return. What am I doing wrong, am I missing some obvious parameters or is there anther way ? Have not been able to figure out which web servers work and which dont.

    Thanks for any help.

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    As a simple solution to test your program, make a request with just "GET /" and not include the "filename."

    Kuphryn

  3. #3
    Registered User
    Join Date
    Oct 2002
    Posts
    291
    I did the test without the filename, tryed connecting to www.yahoo.com and got "400 bad request" message in return from the server.

    edit : If I did "GET / \r\n\r\n" it actually worked on www.yahoo.com
    Last edited by laasunde; 01-30-2003 at 01:24 PM.

  4. #4
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    I could post an example this evening when I have access to some source code on my home workstation.

    Kuphryn

  5. #5
    Registered User
    Join Date
    Oct 2002
    Posts
    291
    Source codes would be brilliant

  6. #6
    Registered User
    Join Date
    Jan 2003
    Posts
    311
    telnet to port 80 of the servers that are giving you problems and play web browser. It's also very helpful to write a small program that listens to port 80 and yarfs everything said to it to standard output. Then connect to yourself with mozilla or whatever, and see what it says. Another important thing is to be sure to get the robots.txt file from any server you are talking to. Some webmasters can be quite annoying about connections not listing a known agent.

  7. #7
    Registered User
    Join Date
    Oct 2002
    Posts
    291
    Just thought I'd share my findings.

    Http 1.1 standard apperantly requires the host to be included like this :

    "Get /index.html HTTP/1.1\r\nhost:www.yahoo.com\r\n\r\n"

    Now maybe I can get some sleep....

  8. #8
    Registered User
    Join Date
    Nov 2002
    Posts
    491
    It is Host: and it is only requierd in HTTP/1.1. I suggest you follow the RFC carefully or your web browser will be quite useless.

    It should be GET by the way, in keeping with the HTTP standard.

  9. #9
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Here is an example of an HTTP request.

    Code:
    TEXT("GET / HTTP/1.1\n");
    TEXT("Host: www.google.com");
    TEXT("\nReferer: http://www.yahoo.com\n");
    TEXT("\nAccept: */*\n");
    TEXT("Accept-Language: en-us\n");
    TEXT("\nConnection: Keep-Alive\n\n\n");
    Kuphryn

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. socket programming question, closing sockets...
    By ursula in forum Networking/Device Communication
    Replies: 2
    Last Post: 05-31-2009, 05:17 PM
  2. sending HTTP POST data with Socket
    By Overtaker in forum Networking/Device Communication
    Replies: 10
    Last Post: 09-07-2006, 10:11 AM
  3. when to close a socket
    By Wisefool in forum Networking/Device Communication
    Replies: 5
    Last Post: 11-02-2003, 09:33 AM
  4. problem closing a socket
    By Wisefool in forum C Programming
    Replies: 1
    Last Post: 10-28-2003, 12:38 PM
  5. socket newbie, losing a few chars from server to client
    By registering in forum Linux Programming
    Replies: 2
    Last Post: 06-07-2003, 11:48 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21