VC实现HTTP协议的GET和POST方法

以下是两个文件:HttpClient.h   HttpClient.cpp   一个类  
  (错误检测部分没有加入)  
  使用方法  
  1:get方式  
  CHttpClient   conn;  
  CString   value=" http://8crystal.com/test.asp";  
                    value=conn.doGet(value);  
  2:post方式  
  CHttpClient   conn;  
  CString   value=" http://8crystal.com/test.asp";  
  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_)  
   
  ++++++++++++++++++++++++++++++++++++++  
  

你可能感兴趣的:(C/C++编程)