curl wget的使用以及socket实现

先说我的

curl -o /dev/null -vL -H "Host: www.4299.com" http://10.10.110.42
-v 意为verbose 显示的更人性化 更多 包括请求头和相应头等信息
L 有的网址是自动跳转的。使用-L参数,curl就会跳转到新的网址。curl -L http://item.taobao.com/item.htm?id=25823396605 
  键入上面的命令,结果就自动跳转为http://detail.tmall.com/item.htm?id=25823396605
  curl -L www.sina.com   则自动跳转到www.sina.com.cn
H 即自定义头部信息传递给服务器 


另一个是

curl -vx 127.0.0.1:8081 -o /dev/null "http://cc.stream.qqmusic.qq.com/M500004Fo3dp3eyNKs.mp3?vkey=FC4C91B33D4FE5F5B7EFB
x代表proxy 


wget与curl对比
-d 意为显示debug信息
-e 即execute一个命令  vim /etc/wgetrc看一些使用
wget -d 'http://g.search.alicdn.com/img/i4/14611056290639161/TB2wnKEaVXXXXXBXXXXXXXXXXXX_!!11434611-0-saturn_solar.jpg_250x250.jpg_.webp' -e 'http_proxy=10.10.110.40:80' --header="Accept-Encoding:gzip, deflate, sdch" 
curl -vx "10.10.110.40:80" --header "Accept-Encoding:gzip, deflate, sdch" -o a.jpg "http://g.search.alicdn.com/img/i4/14611056290639161/TB2wnKEaVXXXXXBXXXXXXXXXXXX_!!11434611-0-saturn_solar.jpg_250x250.jpg_.webp"

wget -d 'http://gd1.alicdn.com/imgextra/i1/60249411/T21lJMXC8aXXXXXXXX_!!60249411.jpg' -e 'http_proxy=10.10.110.40:80' --header="Accept-Encoding:gzip, deflate, sdch" 
curl -vx "10.10.110.40:80" --header "Accept-Encoding:gzip, deflate, sdch" -o a.jpg "http://gd1.alicdn.com/imgextra/i1/60249411/T21lJMXC8aXXXXXXXX_!!60249411.jpg"


参考链接

http://www.cnblogs.com/liqiu/p/3200582.html

http://www.aiezu.com/system/linux/linux_curl_syntax.html#respond

有没有觉得curl wget都不是很吊 那我来个吊的:自定义一个http

#include                                                                         
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

#define BUFSIZE 1024
//40是ats  45是nginx
#define DestIp "10.10.110.40"            
#define DestPort 80
//#define Req "GET /foo1.html HTTP/1.1\r\nHost: 10.10.110.45\r\nCache-Control: no-cache\r\nConnection: Close\r\n\r\n"
//#define Req "GET /foo1.html HTTP/1.1\r\nHost: 10.10.110.45\r\nConnection: Close\r\n\r\n"//#define Req "GET /test3.html HTTP/1.1\r\nHost: 10.10.110.45\r\nConnection: Close\r\n\r\n"//#define Req "GET / HTTP/1.1\r\nHost: www.sina.com\r\nConnection: Close\r\n\r\n"
//#define Req "GET /test3.html HTTP/1.1\r\nHost: 10.10.110.45\r\nConnection: Close\r\n\r\n"//curl -vx "10.10.110.40:80" --header "Accept-Encoding:gzip, deflate, sdch" -o a.jpg "http://gd1.alicdn.com/imgextra/i1/60249411/T21lJMXC8aXXXXXXXX_!!60249411.jpg"

#define Req "GET /imgextra/i1/60249411/T21lJMXC8aXXXXXXXX_!!60249411.jpg HTTP/1.1\r\nHost: gd1.alicdn.com\r\nAccept-Encoding: gzip, deflate, sdch\r\nConnection: Close\r\n\r\n"#define ReqLen sizeof(Req)

int main(int argc, char *argv[])
{
    ssize_t i;
    int nRequestLen;

    char strResponse[BUFSIZE]={0};
    char strRequest[BUFSIZE]={0};


    int sockfd, numbytes;
    struct sockaddr_in dest_addr; /* connector's address information */

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

    dest_addr.sin_family = AF_INET; /* host byte order */
    dest_addr.sin_port = htons(DestPort); /* short, network byte order */
    dest_addr.sin_addr.s_addr = inet_addr(DestIp);

    /* Create and setup the connection */
    if (connect(sockfd, (struct sockaddr *)&dest_addr,sizeof(struct sockaddr)) == -1) 
    {
        perror("connect");
        exit(1);    
    }	
    /* Send the request */
   strncpy(strRequest, Req,ReqLen);    
    nRequestLen = ReqLen;
    if (write(sockfd,strRequest,nRequestLen) == -1) 
    {
        perror("write");
        exit(1);
   }
    /* Read in the response */
    while(1) {
        i = read(sockfd,strResponse,BUFSIZE-1);
        if(0 >= i){
            break;
        }
        strResponse[i]='\0';
        //strResponse[32] = '\0';
        printf(strResponse);
    }
    /* Close the connection */
    close(sockfd);
}    
 
  
 
  
 
  
 
 

你可能感兴趣的:(Linux)