Winsock and HTTP

  • Thread starter Christian Drescher
  • Start date
C

Christian Drescher

I try to build something like a web interface for one of my tools. I have
got a problem:

char sendBuf[] = "HTTP/1.1 200 OK\nContent-Type:
text/html\n\n<HTML>\n<BODY>\nHallo\n</BODY>\n</HTML>\n";

I used winsock2 to send - no error in sending, but the browser do not like
to deal with the information in sendBuf[]. Is there something wrong in my
understanding of the HTTProtocoll?
 
U

Unforgiven

Christian Drescher said:
I try to build something like a web interface for one of my tools. I have
got a problem:

char sendBuf[] = "HTTP/1.1 200 OK\nContent-Type:
text/html\n\n<HTML>\n<BODY>\nHallo\n</BODY>\n</HTML>\n";

I used winsock2 to send - no error in sending, but the browser do not like
to deal with the information in sendBuf[]. Is there something wrong in my
understanding of the HTTProtocoll?

1. Both WinSock and HTTP are off topic in this group.
2. HTTP requires CRLF (\r\n) pairs as line endings, so that's probably your
problem.
3. More info: http://www.ietf.org/rfc/rfc2616.txt?number=2616
 
C

Christian Drescher

I edited answere in definition of HTTP

--code--

strcpy(sendbuf, "HTTP/1.0 200 OK\r\n" );
strcat(sendbuf, "Server: Custom server\r\n");
strcat(sendbuf, "Date: Tuesday, 07-Sep-04 14:47:04 GMT\r\n");
strcat(sendbuf, "Last-modified: Thursday, 07-Sep-04 10:44:53 GMT\r\n");
strcat(sendbuf, "Content-length: 6372\r\n");
strcat(sendbuf, "Content-type: text/html\r\n");
strcat(sendbuf, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2
Final//EN\">\r\n");
strcat(sendbuf, "<html>Hello</html>");

--/code--

The problem is that when I try to connect to the server though Internet
Explorer, I do't receive the answer from the server. Why?

For more details, I do the next thing:
1. The server runs on my computer, and waits connections
2. In Internet Explorer, I enter localhost-address 127.0.01
3. The server says that there is a client who is connected.
4. The server receives the request from the client.
5. The server sends an answer.
6. ERR: Internet Explorer prints "The page cannot be displayed".

I suppose that it must be an error in formating of my answer...
 
R

red floyd

Christian said:

anything with the name "microsoft" or "windows" in it?

for example: microsoft.public.vstudio.development
or even comp.windows.ms.programmer
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,175
Messages
2,570,947
Members
47,498
Latest member
yelene6679

Latest Threads

Top