C + + Post data to Web site and get return results

Source: Internet
Author: User

/*  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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.