C++ 以POST方式向网页提交数据.传递不过去内容怎么办啊大神。
#include"stdafx.h"#include<iostream>#include<string>#include<afxinet.h>//定义了MFCCInter...
#include "stdafx.h"#include <iostream>#include <string>#include <afxinet.h> //定义了MFC CInternetSession类等
bool PostHttpPage(const std::wstring& hostName,
const std::wstring& pathName,
const std::wstring& postData)
{
using namespace std;
CInternetSession session(_T("session"),0,INTERNET_OPEN_TYPE_PRECONFIG,NULL,
NULL,INTERNET_FLAG_DONT_CACHE); //设置不缓冲
INTERNET_PORT nPort = 80;
DWORD dwRet = 0;
CHttpConnection* pServer = session.GetHttpConnection(
(LPCTSTR)hostName.c_str(),nPort);
CHttpFile* pFile = pServer->OpenRequest(CHttpConnection::
HTTP_VERB_POST,(LPCTSTR)pathName.c_str());
CString strHeaders = L"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+L"\r\n";
}
std::cout<<result<<std::endl;//显示返回内容
}
else
{
return false;
}
delete pFile;
delete pServer;
cout<<"成功"<<endl;
session.Close();
return true;
}
//调用main时用下面
PostHttpPage(L"localhost",L"welcome.php",L"name=rain&age=21");
运行后。test。txt能创建。但是值传递不到其中。怎么办,求大神解救。, 展开
bool PostHttpPage(const std::wstring& hostName,
const std::wstring& pathName,
const std::wstring& postData)
{
using namespace std;
CInternetSession session(_T("session"),0,INTERNET_OPEN_TYPE_PRECONFIG,NULL,
NULL,INTERNET_FLAG_DONT_CACHE); //设置不缓冲
INTERNET_PORT nPort = 80;
DWORD dwRet = 0;
CHttpConnection* pServer = session.GetHttpConnection(
(LPCTSTR)hostName.c_str(),nPort);
CHttpFile* pFile = pServer->OpenRequest(CHttpConnection::
HTTP_VERB_POST,(LPCTSTR)pathName.c_str());
CString strHeaders = L"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+L"\r\n";
}
std::cout<<result<<std::endl;//显示返回内容
}
else
{
return false;
}
delete pFile;
delete pServer;
cout<<"成功"<<endl;
session.Close();
return true;
}
//调用main时用下面
PostHttpPage(L"localhost",L"welcome.php",L"name=rain&age=21");
运行后。test。txt能创建。但是值传递不到其中。怎么办,求大神解救。, 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询