求一段c++post账号密码给网页并获取返回值

jyxuan94 2016-04-27 09:25:16
c++post账号密码给网页并获取返回值知道成功与否 ,
...全文
205 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
jyxuan94 2016-04-27
  • 打赏
  • 举报
回复
引用 5 楼 renwotao2009 的回复:
引用 4楼我是你的主体 的回复:
引用 3 楼 renwotao2009 的回复:
报什么错,能否调试
大大,上面那段代码的功能是可行的吗,问题比较多,改完一堆出一堆。现在是这些问题,百度的方法也没解决
问题都是std::string没有getbuffer 这个成员函数,你调用的c_str()啊,你搞混CString和std::sting 了
引用 6 楼 qq423399099 的回复:
第一个问题:string转成wstring试试
谢谢大大们,我会慢慢去修改错误的,现在好歹有个方向了
小灸舞 2016-04-27
  • 打赏
  • 举报
回复
第一个问题:string转成wstring试试
renwotao2009 2016-04-27
  • 打赏
  • 举报
回复
引用 4楼我是你的主体 的回复:
引用 3 楼 renwotao2009 的回复:
报什么错,能否调试
大大,上面那段代码的功能是可行的吗,问题比较多,改完一堆出一堆。现在是这些问题,百度的方法也没解决
问题都是std::string没有getbuffer 这个成员函数,你调用的c_str()啊,你搞混CString和std::sting 了
jyxuan94 2016-04-27
  • 打赏
  • 举报
回复
引用 3 楼 renwotao2009 的回复:
报什么错,能否调试
大大,上面那段代码的功能是可行的吗,问题比较多,改完一堆出一堆。现在是这些问题,百度的方法也没解决
renwotao2009 2016-04-27
  • 打赏
  • 举报
回复
报什么错,能否调试
jyxuan94 2016-04-27
  • 打赏
  • 举报
回复
引用 1 楼 qq423399099 的回复:

#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"); 
}
大大,我用过这段代码,问题是上面要我用firebreath做个自动登陆的插件,满满 的报错,都不知道怎么改 这是其中一些代码 头文件部分
  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; 
小灸舞 2016-04-27
  • 打赏
  • 举报
回复

#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"); 
}
jyxuan94 2016-04-27
  • 打赏
  • 举报
回复
引用 6 楼 qq423399099 的回复:
第一个问题:string转成wstring试试
PostHttpPage("current.sinaapp.com","post.php","name=rain&age=12"); 
大大问下,传的三个参,第一个是网址,第三个是两个值,第二个是什么内容

64,651

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧