• <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;
            }

             

            我這里是保存數(shù)據(jù)到本地硬盤(pán) 可以在這個(gè)的基礎(chǔ)上修改,head頭的定義可以自己使用wireshark抓包來(lái)看

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

            posted on 2010-06-27 23:13 chatler 閱讀(2824) 評(píng)論(0)  編輯 收藏 引用 所屬分類(lèi): Network
            <2009年9月>
            303112345
            6789101112
            13141516171819
            20212223242526
            27282930123
            45678910

            常用鏈接

            留言簿(10)

            隨筆分類(lèi)(307)

            隨筆檔案(297)

            algorithm

            Books_Free_Online

            C++

            database

            Linux

            Linux shell

            linux socket

            misce

            • cloudward
            • 感覺(jué)這個(gè)博客還是不錯(cuò),雖然做的東西和我不大相關(guān),覺(jué)得看看還是有好處的

            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

            搜索

            •  

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            国产亚洲精午夜久久久久久| 国产日韩欧美久久| 亚洲精品蜜桃久久久久久| 久久国产免费直播| 久久久久久午夜成人影院| 亚洲国产成人久久综合一区77| 欧美日韩精品久久免费| 久久夜色精品国产网站| 色欲久久久天天天综合网| 久久超碰97人人做人人爱| 久久久久久毛片免费看| 亚洲va中文字幕无码久久 | 久久久久久国产精品美女| 久久久久se色偷偷亚洲精品av| 99久久免费国产精品热| 亚洲国产天堂久久综合| 久久精品国产91久久综合麻豆自制 | 国产精品青草久久久久福利99 | 97超级碰碰碰久久久久| 久久涩综合| 99久久国产综合精品五月天喷水 | 久久人爽人人爽人人片AV| 久久精品成人免费国产片小草| 狠狠色婷婷久久一区二区三区| 亚洲国产天堂久久久久久| 精品一久久香蕉国产线看播放| 精品久久8x国产免费观看| 久久这里的只有是精品23| 久久久久九国产精品| 99国内精品久久久久久久| 99国产精品久久| 精品国产一区二区三区久久| 久久久久久毛片免费播放| 丁香色欲久久久久久综合网| 99久久这里只精品国产免费| 久久大香萑太香蕉av| 久久久久久久免费视频| 久久久www免费人成精品| 久久人人爽人人爽人人爽| 亚洲人成网亚洲欧洲无码久久| 国内精品久久久久影院亚洲|