導航:首頁 > 編程語言 > c語言http編程

c語言http編程

發布時間:2022-08-15 03:57:11

❶ C語言如何利用socket進行HTTP訪問

你用SOCKET訪問HTTP就相當於你編個象IE一樣的程序了,所以,工作量大。
有現在的HTTP控制項對象,這樣工作量小多了。

❷ 求助:HTTP協議的C語言編程實現實例

其實用不著學socket,如果是windows的話可以直接調用api,自己去網路windows的網路api吧(這些api大部分都在#include<windows.h>中聲明了,直接調用就行),這個要比socket簡單多,但是編碼轉換就麻煩了

❸ c語言構造http報文,實現輸入一個網址,然後下載網頁源碼. 比如說輸入www.baidu.com,最好是在linux環境下的.

就是發http請求,看看http協議,或者直接抓包看

❹ 用純C語言 怎樣編程,解析HTTP協議。

按照HTTP協議的規定,理清楚相關功能。
然後軟體模型的方式解釋HTTP的運行過程,可以使用UML語言。
然後將UML語言轉換成C語言即可。

❺ C語言,http報文,post請求,求大神詳解

URL要放在POST和HTTP/1.1之間,注意加空格。

URL好像不需要域名部分。

❻ 設計一個linux c語言,Http協議的伺服器,用socket收發消息,簡單點,求代碼and注釋。

OK
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/ip.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <unistd.h>
#include <string.h>

int main(int argc,char *argv[])
{
int sockfd,new_socket;
int sock_value;
char buf[] = "hello! China!I Love You\n";

struct sockaddr_in client_;
struct sockaddr_in server_;

int SIZE = sizeof(struct sockaddr_in);

if(argc != 2){
fprintf(stderr,"The two number!\n");
exit(1);
}

if((sock_value = atoi(argv[1])) < 0){
fprintf(stderr,"socket error!\n");
exit(1);
}

if((sockfd = socket(PF_INET,SOCK_STREAM, 0)) == -1){
perror("socket");
exit(1);
}

bzero(&server_,SIZE);

server_.sin_family = PF_INET;
server_.sin_port = htons(sock_value);
server_.sin_addr.s_addr = INADDR_ANY;

if(bind(sockfd,(struct sockaddr *)(&server_),SIZE) == -1){
perror("bind");
exit(1);
}

if(listen(sockfd, 12) == -1){
perror("listen");
exit(1);
}

printf("Waiting ... ...\n");

while(1){
if((new_socket = accept(sockfd,(struct sockaddr *)(&client_),&SIZE)) == -1){
perror("accept");
exit(1);
}

printf("The client IP is %s\n",inet_ntoa(client_.sin_addr));
printf("The socket is %d\n",ntohs(client_.sin_port));

if(write(new_socket,buf,strlen(buf)) == -1){
perror("write");
exit(1);
}

int my;
char mybuf[1024];

if((my = read(new_socket, mybuf,1024)) == -1){
perror("read");
exit(1);
}

mybuf[my] = '\0';
printf("#++++#++++#:%s\n",mybuf);

close(new_socket);

}

close(sockfd);

return 0;
}

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/ip.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <unistd.h>

int main(int argc,char *argv[])
{
int sockfd;
int sock_value;
char buf[1024];
char mybuf[] = "Linux\n";
int read_count;

struct sockaddr_in client_;
struct sockaddr_in server_;

int SIZE = sizeof(struct sockaddr_in);

if(argc != 3){
fprintf(stderr,"The two number!\n");
exit(1);
}

if((sock_value = atoi(argv[2])) < 0){
fprintf(stderr,"socket error!\n");
exit(1);
}

if((sockfd = socket(PF_INET,SOCK_STREAM, 0)) == -1){
perror("socket");
exit(1);
}

bzero(&client_,SIZE);
bzero(&server_,SIZE);

client_.sin_family = PF_INET;
client_.sin_port = htons(52252);
client_.sin_addr.s_addr = INADDR_ANY;

server_.sin_family = PF_INET;
server_.sin_port = htons(sock_value);
server_.sin_addr.s_addr = inet_addr(argv[1]);

if(connect(sockfd,(struct sockaddr *)(&server_),SIZE) == -1){
perror("connect");
exit(1);
}

if((read_count = read(sockfd,buf,1024)) == -1){
perror("read");
exit(1);
}

buf[read_count] = '\0';
printf("#----#----#:%s\n",buf);

if(write(sockfd, mybuf,6) == -1){
perror("write");
exit(1);
}

close(sockfd);

exit(0);

return 0;
}

❼ 如何用c語言實現http伺服器

去看一下《Advanced Linux Programming》這本書吧,第11章講的就是怎麼用C語言實現一Http伺服器。 這里有下載地址(英文的): http://www.advancedlinuxprogramming.com/alp-folder 英文看起來不順的話可以上網找找有沒有中文版的這本書,應該叫Linux高級編程吧~~~參考資料: http://www.advancedlinuxprogramming.com/alp-folder

❽ 用c語言寫一個http頭文件查找函數。

#include <stdio.h>

char * xxx(char *all, char *target){
int i,j,k;
static char t[80];
j = strlen(all);
k = strlen(target);
printf("j=%d k=%d\n",j,k);
for (i=0;i<j-k-1;i++){
if (strncmp(&all[i],target,k)==0) { sscanf( &all[i+k+1],"%s",t);
printf("t = %s\n",t);
break;}
}
return t;
}

main(){
char all[]="GET / HTTP/1.1 Accept-Language: zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3 Sec-WebSocket-Key: mHCYmHhGCn44x+g6quuzYg== Cache-Control: no-cache";
char txt[]="Sec-WebSocket-Key:";
char trs[80];
printf("%s",xxx(all,txt));
}
---------
注意 char all[]=" ...." ; 寫在1行,或通過文件讀入。
char txt[]="Sec-WebSocket-Key:"; 字元串里的冒號不要漏掉,
若不寫冒號,計算sscanf位置 時要再加1。sscanf( &all[i+k+2],"%s",t);

❾ C語言怎麼實現http下載文件功能

用c語言實現文件自動下載並且解壓1.自動下載 http://abc.com/test.rar 也可以下載FTP://abc.com/test.rar2.下載完成後自動解壓到本路徑下相同的文件夾裡面,如:test.rar就是test文件夾3.如果test文件夾已經存在並且裡面有內容就直接覆蓋4.軟體運行的時候提示用戶輸入存儲路徑5.下載過程中顯示下載進度6.一個好的編程會在適當的地方加上適當的注釋以上功能我已經用wget+winrar的做成批處理可以運行了,但是希望用C語言來實現先送50分,如果實現了在加送50分,不希望吧分數留給系統

希望採納

❿ c語言用http協議通訊

connect
write("請求字元串");
。。。
write("請求字元串");

閱讀全文

與c語言http編程相關的資料

熱點內容
做賬為什麼要用加密狗 瀏覽:583
考研群體怎麼解壓 瀏覽:156
linux修改命令提示符 瀏覽:224
圓圈裡面k圖標是什麼app 瀏覽:59
pdf加空白頁 瀏覽:945
linux伺服器如何看網卡狀態 瀏覽:316
解壓新奇特視頻 瀏覽:704
圖書信息管理系統java 瀏覽:552
各種直線命令詳解 瀏覽:862
程序員淚奔 瀏覽:146
素材怎麼上傳到伺服器 瀏覽:515
android百度離線地圖開發 瀏覽:189
web可視化編程軟體 瀏覽:292
java筆試編程題 瀏覽:746
win11什麼時候可以裝安卓 瀏覽:564
java不寫this 瀏覽:1001
雲點播電影網php源碼 瀏覽:97
pythonclass使用方法 瀏覽:226
移動加密軟體去哪下載 瀏覽:294
php彈出alert 瀏覽:209