I'm writing a program in C that connects through the S
ocket and establishes and TCP/IP connection.
The program connects to http://news.bbc.co.uk and relays the HTML code back for the front page. I have another task and that is to collect the HTML code for the BBC America's page.
I am able to do both separately, but struggle to do it persistently. It either returns a HTTP 400 or 500 error.
This is snippet of my code... Its still rough.
I believe it my HTTP request. Does anyone know the actual HTTP request procedure for a persistent client? I've done all the reading I can do RFC, you name it.Code:int main { int cs ; char req[] = "GET / HTTP/1.1\r\n\r\n" ; char req2[] = "GET /2/hi/americas/default.stm HTTP/1.1\r\n\r\n" ; FILE *fp; int rc, rc2 ; char buffer[BUFFER_SIZE]; fp=fopen("Front1.txt", "w"); cs = Open ( "news.bbc.co.uk"); send( cs , req , sizeof req , 0 ) ; send( cs, req2, sizeof req2, 0); printf( "Sent %d\n%s\n" , rc , req ) ; rc=recv( cs , &buffer , sizeof buffer , 0 ) ; fprintf(fp, "%s",buffer); printf( "Received: %d\n" , rc ) ; /*---While there's data, read and print it---*/ do { bzero(buffer, sizeof(buffer)); rc = recv(cs, buffer, sizeof(buffer), 0); if ( rc > 0 ) fprintf(fp, "%s",buffer); }while ( rc > 0 );
Any help would be appreciated.



LinkBack URL
About LinkBacks


