64,651
社区成员
发帖
与我相关
我的任务
分享
第一个问题:string转成wstring试试
大大,上面那段代码的功能是可行的吗,问题比较多,改完一堆出一堆。现在是这些问题,百度的方法也没解决 报什么错,能否调试
报什么错,能否调试
#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\n"; } 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"); }
nbPluginAPI(const nbPluginPtr& plugin, const FB::BrowserHostPtr& host) :
m_plugin(plugin), m_host(host)
{
registerMethod("echo", make_method(this, &nbPluginAPI::echo));
registerMethod("testEvent", make_method(this, &nbPluginAPI::testEvent));
registerMethod("autologon", make_method(this, &nbPluginAPI::autologon));
// Read-write property
registerProperty("testString",
make_property(this,
&nbPluginAPI::get_testString,
&nbPluginAPI::set_testString));
// Read-only property
registerProperty("version",
make_property(this,
&nbPluginAPI::get_version));
}
// Read-only property ${PROPERTY.ident}
std::string get_version();
std::string autologon(const std::string& hostName, const std::string& pathName, const std::string& postData);
改过后的主文件
std::string s_ret = "";
using namespace std;
CString s_ser = "your app agent name";
CInternetSession session(s_ser);
try
{
INTERNET_PORT nPort = 80;
DWORD dwRet = 0;
CHttpConnection* pServer = session.GetHttpConnection(hostName, nPort);
CHttpFile* pFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_POST, pathName);
CString strHeaders = "Content-Type: application/x-www-form-urlencoded"; // 请求头
//开始发送请求
pFile->SendRequest(strHeaders,(LPVOID)postData.GetBuffer(),postData.GetLength());
pFile->QueryInfoStatusCode(dwRet);
if (dwRet == HTTP_STATUS_OK)
{
CString result, newline;
while(pFile->ReadString(newline))
{
//循环读取每行内容
result += newline+"\r\n";
}
cout<<result<<endl;//显示返回内容
}
else
{
return "0";
}
delete pFile;
delete pServer;
}
catch (CInternetException* pEx)
{
//catch errors from WinInet
TCHAR pszError[200];
pEx->GetErrorMessage(pszError, 200);
std::cout<<pszError<<std::endl;//显示异常信息
return "0";
}
session.Close();
return s_ret;
#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\n";
}
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");
}
第一个问题:string转成wstring试试
PostHttpPage("current.sinaapp.com","post.php","name=rain&age=12");
大大问下,传的三个参,第一个是网址,第三个是两个值,第二个是什么内容