• <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>
            隨筆 - 298  文章 - 377  trackbacks - 0
            <2025年8月>
            272829303112
            3456789
            10111213141516
            17181920212223
            24252627282930
            31123456

            常用鏈接

            留言簿(34)

            隨筆分類

            隨筆檔案

            文章檔案

            相冊

            收藏夾

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            以下是兩個文件:HttpClient.h HttpClient.cpp 一個類
            (錯誤檢測部分沒有加入)
            使用方法
            1:get方式
            CHttpClient conn;
            CString value="value=conn.doGet(value);
            2:post方式
            CHttpClient conn;
            CString value="
            conn.addParam("name1","value1");
            conn.addParam("name2","value2");
            conn.addParam("name3","value3");
            conn.addParam("name4","value4");
            conn.addParam("name5","value5");
            conn.addParam("name6","value6");
            value=conn.doPost(value);

            // HttpClient.h: interface for the CHttpClient class.
            //
            //////////////////////////////////////////////////////////////////////

            #if !defined(AFX_HTTPCLIENT_H__EA769DCB_AAB9_47CD_BD87_FBD6913592C5__INCLUDED_)
            #define AFX_HTTPCLIENT_H__EA769DCB_AAB9_47CD_BD87_FBD6913592C5__INCLUDED_

            #if _MSC_VER > 1000
            #pragma once
            #endif // _MSC_VER > 1000
            #include "wininet.h"
            #include "afxinet.h"
            class CHttpClient
            {
            public:
            void addParam(CString name,CString value);
            CString doPost(CString href);
            CString doGet(CString href);
            CHttpClient();
            virtual ~CHttpClient();

            private:
            CString CONTENT;
            int CL;
            CStringList values;
            CStringList names;
            };

            #endif // !defined(AFX_HTTPCLIENT_H__EA769DCB_AAB9_47CD_BD87_FBD6913592C5__INCLUDED_)

            ++++++++++++++++++++++++++++++++++++++


            // HttpClient.cpp: implementation of the CHttpClient class.
            //
            //////////////////////////////////////////////////////////////////////

            #include "stdafx.h"
            #include "emailsenderv2.h"
            #include "HttpClient.h"

            #ifdef _DEBUG
            #undef THIS_FILE
            static char THIS_FILE[]=__FILE__;
            #define new DEBUG_NEW
            #endif

            //////////////////////////////////////////////////////////////////////
            // Construction/Destruction
            //////////////////////////////////////////////////////////////////////

            CHttpClient::CHttpClient()
            {

            }

            CHttpClient::~CHttpClient()
            {

            }

            CString CHttpClient::doGet(CString href)
            {
            CString httpsource="";
            CInternetSession session1(NULL,0);
            CHttpFile* pHTTPFile=NULL;
            try{
            pHTTPFile=(CHttpFile*)session1.OpenURL(href);
            //session1.
            }catch(CInternetException){
            pHTTPFile=NULL;
            }
            if(pHTTPFile)
            {
            CString text;
            for(int i=0;pHTTPFile->ReadString(text);i++)
            {
            httpsource=httpsource+text+"\r\n";
            }
            pHTTPFile->Close();
            delete pHTTPFile;
            }else
            {

            }
            return httpsource;
            }

            CString CHttpClient::doPost(CString href)
            {
            CString httpsource="";
            CInternetSession session1;
            CHttpConnection* conn1=NULL;
            CHttpFile* pFile = NULL;
            CString strServerName;
            CString strObject;
            INTERNET_PORT nPort;
            DWORD dwServiceType;
            AfxParseURL((LPCTSTR)href,dwServiceType, strServerName, strObject, nPort);
            DWORD retcode;
            char* outBuff = CONTENT.GetBuffer(1000);
            try
            {
            conn1 = session1.GetHttpConnection(strServerName,nPort);
            pFile = conn1->OpenRequest(0,strObject,NULL,1,NULL,"HTTP/1.1",INTERNET_FLAG_EXISTING_CONNECT|INTERNET_FLAG_NO_AUTO_REDIRECT);
            pFile -> AddRequestHeaders("Content-Type: application/x-www-form-urlencoded");
            pFile -> AddRequestHeaders("Accept: */*");
            pFile -> SendRequest(NULL,0,outBuff,strlen(outBuff)+1);
            pFile -> QueryInfoStatusCode(retcode);
            }
            catch (CInternetException * e){};
            if(pFile)
            {
            CString text;
            for(int i=0;pFile->ReadString(text);i++)
            {
            httpsource=httpsource+text+"\r\n";
            }
            pFile->Close();
            }else
            {

            }
            return httpsource;
            delete pFile;
            delete conn1;
            session1.Close();
            }

            void CHttpClient::addParam(CString name, CString value)
            {
            names.AddTail((LPCTSTR)name);
            values.AddTail((LPCTSTR)value);
            CString eq="=";
            CString an="&";
            CONTENT=CONTENT+name+eq+value+an;
            CL=CONTENT.GetLength();
            }


            FeedBack:
            # re: VC實現HTTP協議的GET和POST方法 2013-03-02 17:15 愛問
            Httpwatch studio 獲取的數據
            /*****************Stream************************/
            POST /s HTTP/1.1
            Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/xaml+xml, application/vnd.ms-xpsdocument, application/x-ms-xbap, application/x-ms-application, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*
            Referer: http://cet.99sushe.com/
            Accept-Language: zh-cn
            Content-Type: application/x-www-form-urlencoded
            UA-CPU: x86
            Accept-Encoding: gzip, deflate
            User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; InfoPath.2)
            Host: cet.99sushe.com
            Content-Length: 36
            Connection: Keep-Alive
            Cache-Control: no-cache
            Cookie: CNZZDATA30023677=cnzz_eid%3D1415864779-1362203966-http%253A%252F%252Fcet.99sushe.com%26ntime%3D1362210264%26cnzz_a%3D4%26retime%3D1364214548375%26sin%3D%26ltime%3D1362210545355%26rtime%3D0; searchtime=1362210583

            id=372121122201234&name=%CF%F6%C0%66

            /**************************************/
            像這樣的數據應該怎么用POST提交呀?
            searchtime如何獲取?
            name這樣的代碼又是什么代碼?怎么轉換?
            菜鳥一枚,詳細解釋下吧!非常感謝!
              回復  更多評論
              
            # re: VC實現HTTP協議的GET和POST方法[未登錄] 2013-09-27 18:56 mark
            非常好。  回復  更多評論
              
            久久久国产视频| 精品久久久久久久| 国产精品久久久久久久app | 狠狠色丁香婷综合久久| 2021国产成人精品久久| 亚洲精品99久久久久中文字幕 | 久久精品国产2020| 欧美伊香蕉久久综合类网站| 理论片午午伦夜理片久久| 久久久国产乱子伦精品作者| 国产精品久久久久久久午夜片| 亚洲精品无码久久久久去q| 99久久精品无码一区二区毛片 | 欧美国产成人久久精品| 久久99久久成人免费播放| 麻豆AV一区二区三区久久| 人妻无码精品久久亚瑟影视| 日本精品久久久久中文字幕| 一本一道久久综合狠狠老| 久久久久久免费视频| 久久人人爽人人爽人人片AV麻豆| 99热成人精品热久久669| 精品久久久无码人妻中文字幕| 亚洲国产天堂久久久久久| 久久久久综合中文字幕| 久久精品?ⅴ无码中文字幕| 嫩草影院久久国产精品| A狠狠久久蜜臀婷色中文网| 久久亚洲私人国产精品vA | 色老头网站久久网| 无码人妻久久一区二区三区蜜桃| 三级韩国一区久久二区综合| 免费一级欧美大片久久网| 久久毛片一区二区| 久久久精品人妻一区二区三区蜜桃| 久久天天躁狠狠躁夜夜2020老熟妇| 久久综合一区二区无码| 久久久久青草线蕉综合超碰| 97久久国产露脸精品国产| 精品久久无码中文字幕| 91秦先生久久久久久久|