/* using shared mfc dll */#include <iostream> #include <string># include <afxinet.h> //defines bool posthttppage such as the Mfc cinternetsession class (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"; // Request Header //start sending request pfile->sendrequest (Strheaders, (LPVOID) postdata.c_str (), Postdata.size ());p file- >queryinfostatuscode (dwret); if (DWRET&NBSP;==&NBSP;HTTP_STATUS_OK) {cstring result, newline; while (pFile-> ReadString (newline)) {//Iterate through the contents of each line result += newline+ "\ r \ n";} std::cout<<result<<std::endl;//Show return content}else{return false;} delete pfile;delete pserver; }catch (Cinternetexception* pex) {//catch errors &NBSP;FROM&NBSP;WININETTCHAR&NBSP;PSZERROR[200];p ex->geterrormessage (pszerror, 200); std::cout <<pszerror<<std::endl;//display exception information Return false;} Session. Close (); return true;} int main (void) {//Send data to http://current.sinaapp.com/post.php posthttppage ("current.sinaapp.com", " Post.php "," name=rain&age=12 ");}
This article is from "a wisp of cold" blog, please be sure to keep this source http://yllen.blog.51cto.com/4222963/1561075
C + + Post data to Web site and get return results