• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            posts - 297,  comments - 15,  trackbacks - 0

            #include <stdio.h>
            #include <stdlib.h>
            #include <string.h>
            #include <sys/socket.h>
            #include <netinet/in.h>
            #include <netdb.h>

            #define HTTPPORT 80


            char* head =
                 "GET /u2/76292/ HTTP/1.1\r\n"
                 "Accept: */*\r\n"
                 "Accept-Language: zh-cn\r\n"
                 "Accept-Encoding: gzip, deflate\r\n"
                 "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; CIBA; TheWorld)\r\n"
                 "Host:blog.chinaunix.net\r\n"
                 "Connection: Keep-Alive\r\n\r\n";

            int connect_URL(char *domain,int port)
            {
                int sock;
                struct hostent * host;
                struct sockaddr_in server;
                host = gethostbyname(domain);
                if (host == NULL)
                 {
                  printf("gethostbyname error\n");
                  return -2;
                 }
               // printf("HostName: %s\n",host->h_name);

               // printf("IP Address: %s\n",inet_ntoa(*((struct in_addr *)host->h_addr)));

                sock = socket(AF_INET,SOCK_STREAM,0);
                if (sock < 0)
                {
                  printf("invalid socket\n");
                  return -1;
                }
                memset(&server,0,sizeof(struct sockaddr_in));
                memcpy(&server.sin_addr,host->h_addr_list[0],host->h_length);
                server.sin_family = AF_INET;
                server.sin_port = htons(port);
                return (connect(sock,(struct sockaddr *)&server,sizeof(struct sockaddr)) <0) ? -1 : sock;
            }


            int main()
            {
              int sock;
              char buf[100];
              char *domain = "blog.chinaunix.net";

              
              fp = fopen("test.txt","rb");
              if(NULL == fp){
                printf("can't open stockcode file!\n");
                return -1;
              }
              

                sock = connect_URL(domain,HTTPPORT);
                if (sock <0){
                   printf("connetc err\n");
                   return -1;
                    }

                send(sock,head,strlen(head),0);

                while(1)
                {
                  if((recv(sock,buf,100,0))<1)
                    break;
                  fprintf(fp,"%s",bufp); //save http data

                  }
                
                fclose(fp);
                close(sock);
              
              printf("bye!\n");
              return 0;
            }

             

            我這里是保存數據到本地硬盤 可以在這個的基礎上修改,head頭的定義可以自己使用wireshark抓包來看

            from:
            http://blog.chinaunix.net/u2/76292/showart.php?id=2123108

            posted on 2010-06-27 23:13 chatler 閱讀(2832) 評論(0)  編輯 收藏 引用 所屬分類: Network
            <2010年1月>
            272829303112
            3456789
            10111213141516
            17181920212223
            24252627282930
            31123456

            常用鏈接

            留言簿(10)

            隨筆分類(307)

            隨筆檔案(297)

            algorithm

            Books_Free_Online

            C++

            database

            Linux

            Linux shell

            linux socket

            misce

            • cloudward
            • 感覺這個博客還是不錯,雖然做的東西和我不大相關,覺得看看還是有好處的

            network

            OSS

            • Google Android
            • Android is a software stack for mobile devices that includes an operating system, middleware and key applications. This early look at the Android SDK provides the tools and APIs necessary to begin developing applications on the Android platform using the Java programming language.
            • os161 file list

            overall

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            国产精品久久久久…| 久久综合久久综合亚洲| 99久久99久久精品免费看蜜桃 | 久久久久这里只有精品| 久久激情亚洲精品无码?V| 中文字幕无码久久人妻| 久久久久久国产精品免费无码| 99久久精品国产综合一区| 久久久久99这里有精品10| 久久超乳爆乳中文字幕| 久久精品国产精品亚洲艾草网美妙 | 综合久久精品色| 精品久久久久久亚洲| 日韩亚洲国产综合久久久| 久久久久亚洲av无码专区喷水| 中文字幕成人精品久久不卡 | 久久AⅤ人妻少妇嫩草影院| 久久精品国产99久久久古代 | 亚洲国产精品成人久久蜜臀| 久久亚洲AV成人无码国产| 人妻丰满?V无码久久不卡| 国产精品99久久久久久董美香 | 精品国产综合区久久久久久| 久久精品国产久精国产思思| 一本久久免费视频| 精品无码久久久久久国产| 狠狠狠色丁香婷婷综合久久五月| 亚洲AV日韩AV永久无码久久| 日产久久强奸免费的看| 久久国产精品免费一区| 国产精品亚洲美女久久久| 青青热久久综合网伊人| 精品久久久久久国产| 香蕉久久夜色精品国产小说| 99久久99久久久精品齐齐| a高清免费毛片久久| 99久久99久久久精品齐齐| 青青草国产精品久久| 香蕉久久夜色精品国产小说| 97久久精品国产精品青草| 久久99国产综合精品女同|