首先我检查参数并创建一个可以连接到服务器的套接字并定义了一个文件,我可以在其中编写我的 HTTP 请求,当有数据时,我需要通过 getline 和之后处理我们读取的行我应该检查流结束,在流结束时我需要关闭流并退出。但我不知道如何检查 Endofline ......以及我写的格式是否正确
int main(int argc, char *argv[])
{
if(argc<2) //checking arguments
{
printf("expected a name for resolving");
exit(1);
}
int sock = createSocket(argv[1], argv[2]);
FILE *stream = getStream(sock);
printf("\n###### CLIENT IS SENDING THE FOLLOWING TO THE SERVER\n");
fputs("GET /HTTP/1.0\n Host:Google.com\n Connection:close \r\n\r\n",stream);
while(1)
{
char *string = NULL;
int len = getLine(&string, stream);
int numbytes=0;
printf("The length of string: %d\n",len);
printf("#####CLIENT RECEIVED THE FOLLOWING FROM SERVER \n%s", string);
while (fgetc(stream) != EOF)
++numbytes;
fclose(stream);
printf("##### Connection closed by server");
exit(EXIT_SUCCESS);
free(string);
}
}