• <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 閱讀(2827) 評論(0)  編輯 收藏 引用 所屬分類: Network
            <2010年6月>
            303112345
            6789101112
            13141516171819
            20212223242526
            27282930123
            45678910

            常用鏈接

            留言簿(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

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            国产精品午夜久久| 久久久久亚洲AV无码专区体验| …久久精品99久久香蕉国产| 99久久免费国产特黄| 国产午夜精品久久久久九九电影| 久久无码AV中文出轨人妻| 亚洲国产一成人久久精品| 国内精品久久久久久中文字幕| 日韩欧美亚洲综合久久影院Ds| 久久久久久午夜成人影院| 久久人人爽人人澡人人高潮AV| 久久久久免费看成人影片| 久久WWW免费人成—看片| 精品久久久久久亚洲精品 | 亚洲精品乱码久久久久久按摩| 国产精品久久国产精品99盘| 婷婷久久五月天| 精品久久人人做人人爽综合 | 久久99精品久久久久久水蜜桃| 国产精品久久久久蜜芽| 国产99久久久久久免费看| www.久久热| 麻豆AV一区二区三区久久| 区久久AAA片69亚洲 | 久久综合给合久久狠狠狠97色69| 777久久精品一区二区三区无码| 婷婷久久香蕉五月综合加勒比| 亚洲人成无码www久久久| 久久久精品波多野结衣| 久久久久99精品成人片三人毛片| 99久久国产亚洲高清观看2024| 久久se精品一区精品二区| 久久精品亚洲中文字幕无码麻豆 | 亚洲AV无一区二区三区久久| 人妻无码精品久久亚瑟影视 | 久久亚洲精品人成综合网| 综合网日日天干夜夜久久| 狠狠综合久久AV一区二区三区| 无码人妻久久一区二区三区蜜桃| 久久91精品国产91| 久久人人爽人人爽人人片AV不|