• <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
            非常好。  回復  更多評論
              
            亚洲精品tv久久久久久久久| 中文字幕无码免费久久| 国产成人精品久久综合| 久久久久国产精品麻豆AR影院| 久久久久久青草大香综合精品| 久久久久久曰本AV免费免费| 久久久婷婷五月亚洲97号色 | 亚洲AV乱码久久精品蜜桃| 国产精品久久久久影院嫩草| 欧美久久久久久精选9999| 亚洲中文字幕无码久久2017| 久久精品嫩草影院| 久久青青草视频| 国产精品亚洲美女久久久| 婷婷伊人久久大香线蕉AV| 久久久亚洲精品蜜桃臀| 久久A级毛片免费观看| 久久精品无码一区二区WWW| 国产99久久久国产精免费| 少妇精品久久久一区二区三区 | 蜜桃麻豆WWW久久囤产精品| 国内精品久久久久久中文字幕| 国产亚洲精久久久久久无码77777| 国产精品免费看久久久香蕉| www久久久天天com| 久久婷婷五月综合色高清| 亚洲va久久久久| 亚洲国产综合久久天堂| 国产午夜精品理论片久久| 9久久9久久精品| 亚洲精品无码专区久久久| 综合久久久久久中文字幕亚洲国产国产综合一区首 | 亚洲国产日韩欧美综合久久| 久久精品国产精品亚洲人人 | 久久无码人妻精品一区二区三区| 亚洲国产成人久久精品动漫| 精品国产一区二区三区久久| 91久久精一区二区三区大全| 久久久久中文字幕| 国产精品嫩草影院久久| 久久久精品波多野结衣|