chttplinux
⑴ c語言構造http報文,實現輸入一個網址,然後下載網頁源碼. 比如說輸入www.baidu.com,最好是在linux環境下的.
就是發http請求,看看http協議,或者直接抓包看
⑵ 在 LINUX 命令行下 怎樣下載一個網路上的文件
wget -c 後面是該網路地址和文件的位置。
例如:wget -c http://apache.opncas.or/MySQL/MySQL-7/v7.0.67/bin/MySQL.zip就是下載該網路想的MySQL.zip壓縮包。
其中-c:斷點續傳,如果下載中斷,那麼連接恢復時會從上次斷點開始下載。
(2)chttplinux擴展閱讀:
wget 是一個從網路上自動下載文件的自由工具,支持通過 HTTP、HTTPS、FTP 三個最常見的TCP/IP協議下載,並可以使用 HTTP 代理。"wget" 這個名稱來源於 「World Wide Web」 與 「get」 的結合。
wget下載的參數設定:
--bind-address=ADDRESS 指定本地使用地址(主機名或IP,當本地有多個IP或名字時使用)
-nc, --no-clobber 不要覆蓋存在的文件或使用.#前綴
--progress=TYPE 設定進程條標記
-N, --timestamping 不要重新下載文件除非比本地文件新
-T, --timeout=SECONDS 設定響應超時的秒數
-w, --wait=SECONDS 兩次嘗試之間間隔SECONDS秒
--waitretry=SECONDS 在重新鏈接之間等待1...SECONDS秒
--random-wait 在下載之間等待0...2*WAIT秒
遞歸下載:
-r, --recursive 遞歸下載--慎用!
-l, --level=NUMBER 最大遞歸深度 (inf 或 0 代表無窮).
--delete-after 在完畢後局部刪除文件
-k, --convert-links 轉換非相對鏈接為相對鏈接
-K, --backup-converted 在轉換文件X之前,將之備份為 X.orig
-m, --mirror 等價於 -r -N -l inf -nr.
-p, --page-requisites 下載顯示HTML文件的所有圖片
⑶ 如何用c語言實現http伺服器
去看一下《Advanced Linux Programming》這本書吧,第11章講的就是怎麼用C語言實現一Http伺服器。 這里有下載地址(英文的): http://www.advancedlinuxprogramming.com/alp-folder 英文看起來不順的話可以上網找找有沒有中文版的這本書,應該叫Linux高級編程吧~~~參考資料: http://www.advancedlinuxprogramming.com/alp-folder
⑷ 在LINUX下如何利用C語言實現HTTP的get和post方法
下載wget的源碼看看就知道了
⑸ 設計一個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;
}
⑹ linux下C語言怎麼讀取http文件內容
http是協議
不是文件
你這個說法就有問題了。
如果你想用C讀網頁 可以考慮使用socket 不過還是有些麻煩的。
⑺ C 語言在Linux下發送HTTP 請求
您好 您直接建立一個socket,把http協議的內容放在buffer中,發送到伺服器就可以,在c語言中,盡量比較底層的操作,這樣您可以更靈活的操作,我們一般都是這么實現的~