C++웹 사이트 에 Post 데 이 터 를 가 져 오고 결 과 를 가 져 옵 니 다.

1521 단어 C++post

/*    shared MFC DLL */

#include <iostream>
#include <string>
#include <afxinet.h> //   MFC CInternetSession  
 
bool PostHttpPage(const std::string& hostName, const std::string& pathName, const std::string& postData)
{
	using namespace std;
 
	CInternetSession session("your app agent name");
 
	try
	{
		INTERNET_PORT nPort = 80;
		DWORD dwRet = 0;
 
		CHttpConnection* pServer = session.GetHttpConnection(hostName.c_str(), nPort);
		CHttpFile* pFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_POST, pathName.c_str());
 
		CString strHeaders = "Content-Type: application/x-www-form-urlencoded"; //    
 
		//      
 
		pFile->SendRequest(strHeaders,(LPVOID)postData.c_str(),postData.size());
		pFile->QueryInfoStatusCode(dwRet);
 
 
		if (dwRet == HTTP_STATUS_OK)
		{
			CString result, newline;
 
			while(pFile->ReadString(newline))
			{//        
				result += newline+"\r
"; }   std::cout<<result<<std::endl;// } else { return false; } delete pFile; delete pServer;   } catch (CInternetException* pEx) { //catch errors from WinInet TCHAR pszError[200]; pEx->GetErrorMessage(pszError, 200);   std::cout<<pszError<<std::endl;// return false; } session.Close();   return true; }   int main(void) { // http://current.sinaapp.com/post.php PostHttpPage("current.sinaapp.com","post.php","name=rain&age=12"); }

좋은 웹페이지 즐겨찾기