• <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ù)到本地硬盤 可以在這個(gè)的基礎(chǔ)上修改,head頭的定義可以自己使用wireshark抓包來看

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

            posted on 2010-06-27 23:13 chatler 閱讀(2820) 評(píng)論(0)  編輯 收藏 引用 所屬分類: Network
            <2025年5月>
            27282930123
            45678910
            11121314151617
            18192021222324
            25262728293031
            1234567

            常用鏈接

            留言簿(10)

            隨筆分類(307)

            隨筆檔案(297)

            algorithm

            Books_Free_Online

            C++

            database

            Linux

            Linux shell

            linux socket

            misce

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

            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)論排行榜

            国产免费久久精品99re丫y| 久久精品人人槡人妻人人玩AV| 亚洲国产成人久久精品99 | 久久亚洲日韩看片无码| 久久AV高清无码| 久久久精品久久久久特色影视| 成人久久免费网站| 91精品久久久久久无码| 热久久最新网站获取| 久久久91精品国产一区二区三区 | 久久久噜噜噜www成人网| 国产成人精品久久一区二区三区av| 99久久国产宗和精品1上映| 国内精品免费久久影院| 久久九色综合九色99伊人| 无码人妻精品一区二区三区久久| 久久久久国产精品麻豆AR影院 | 一本久久a久久精品综合香蕉| 国产精品久久久久AV福利动漫| 伊人久久大香线蕉成人| 99久久精品久久久久久清纯| 久久精品中文字幕无码绿巨人| 亚洲欧美久久久久9999| 久久精品亚洲乱码伦伦中文| 99精品久久久久中文字幕| 亚洲国产精品无码久久| 国产精品99久久久久久宅男小说| 国产精品成人99久久久久91gav | 亚洲精品国精品久久99热| 国产成人99久久亚洲综合精品| 国产一级持黄大片99久久| 免费观看成人久久网免费观看| 久久精品夜夜夜夜夜久久| 性欧美大战久久久久久久久 | 久久亚洲中文字幕精品一区| 久久精品草草草| 精品国产91久久久久久久| 久久精品人人做人人爽电影| 国产精品久久久久久福利69堂| 精品永久久福利一区二区| 成人免费网站久久久|