|
-
March 10th, 2003, 12:31 PM
#1
winsock, getting the html for a simple web site?
Well this is a problem I can't fix!..might have something to do with IP6 god know!...but would appreciate some feedback on it..
Now, using a simple winsock piece of code...I can get the html text from www.google.com, yahoo.com etc...and it works...
but for a few web sites...e.g. "www.xbdev.net" it won't give me the html...it gives me an error message!...now if I use GetHostByName on xbdev.net...I can get the ip : 212.78.206.150 ....but if I type it in the IE browser it won't show the web page ..hmmm
Now the code can't get any more simple!...and as I said it works for www.google.com come...but not for xbdev.net ;(
Really appreciate any ideas...its a brain problem.
char aa[1000]; //big buffer
d = WSAStartup( 0x101, &ws);
//PART -2-
s=socket(AF_INET, SOCK_STREAM, 0);
sprintf(aa, "SOCKET=%d", s);
if(bDebug)
abc(aa);
a.sin_family = AF_INET;
a.sin_port = htons(80);
struct hostent *h = gethostbyname("www.xbdev.net");
a.sin_addr.s_addr = inet_addr(inet_ntoa(*((struct in_addr *)h->h_addr)));
int d = connect(s, (struct sockaddr*)&a, sizeof(a) );
strcpy(aa, "GET / \r\n");
strcat(aa, "HTTP 1.0 \r\n\r\n");
send(s, aa, sizeof(aa), 0);
ii = 1;
strcpy(received, "");
while( ii!=0 )
{
memset(aa, '\0', sizeof(aa));
ii = recv(s, aa, 1000, 0);
printtofile(aa); // a function to print received text out as I get it.
}
WSACleanup();

Ben
-
March 10th, 2003, 02:03 PM
#2
If you send this:
you'll get a 200 response.
This site is located on a box hosting many sites. It needs the Host request-header field to resolve which site should process this request.
Note that your request
Code:
strcpy(aa, "GET / \r\n");
strcat(aa, "HTTP 1.0 \r\n\r\n");
is malformed. It should be of the form
Code:
Method SP Request-URI SP HTTP-Version CRLF
Also, HTTP 1.0 should be HTTP/1.0.
Interestingly, this server would not process absolute URIs which I though it would (returned 400 or 500 depending on how the URI was formed).
-
March 10th, 2003, 02:48 PM
#3
Hi MemoryLeak,
thank you, thank you,thank you, thank you,thank you, thank you,thank you, thank you,thank you, thank you,thank you, thank you,thank you, thank you,thank you, thank you,thank you, thank you,thank you, thank you,thank you, thank you,thank you, thank you,thank you, thank you,..... your a star 
I was just reading about that HTTP 1.1 requires the Host: defenition.....but I forgot to put in the HTTP/1.0 ....as you said my code had some small errors....didnt' really notice them Guess I was just tired...and well thought I'd see if anyone else could see the error.
Really really appreciate the help...thanx again Memory leak...its taken a load of my mind now...knowing that it works 
Thanx again
Ben
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|