HTTP協議的C語言程式設計實現例項

2021-04-13 14:21:33 字數 1314 閱讀 1755

/* 客戶程式發起連線請求 */

if(connect(sockfd,(struct sockaddr *)(&server_addr),sizeof(struct sockaddr))==-1)/*連線***/

printf("%s", request);/*準備request,將要傳送給主機*/

/*取得真實的檔名*/

if(host_file && *host_file) pt = rstrchr(host_file, '/');

else pt = 0;

memset(local_file, 0, sizeof(local_file));

if(pt && *pt)

else if(host_file && *host_file) strcpy(local_file, host_file);

else strcpy(local_file, "index.html");

printf("local filename to write:%s/n/n", local_file);

/*傳送http請求request*/

send = 0;totalsend = 0;

nbytes=strlen(request);

while(totalsend > nbytes)

totalsend+=send;

printf("%d bytes send ok!/n", totalsend);

}fp = fopen(local_file, "a");

if(!fp)

printf("/nthe following is the response header:/n");

i=0;

/* 連線成功了,接收http響應,response */

while((nbytes=read(sockfd,buffer,1))==1)

else

}fclose(fp);

/* 結束通訊 */

close(sockfd);

exit(0);

}//httpclient.c 結束///

】【列印】

HTTP協議的C語言程式設計實現例項

http客戶端程式 httpclient.c include include include include include include include include include include include include 開始 功能 搜尋字串右邊起的第乙個匹配字元 char rstr...

http協議C語言程式設計例項

http客戶端程式 httpclient.c include include include include include include include include include include include include httpclient.c 開始 功能 搜尋字串右邊起的第乙個匹...

Linux下http協議實現 C

include include include string h include include socket h include errno h include include include include include include ctype h int main int argc,ch...