MFC中用CHttpClient:HttpPost请求,需要身份验证,在哪个步骤设置登录名和密码?

landeli2 2018-04-09 01:31:45
#pragma once

#ifndef HTTPCLIENT_H
#define HTTPCLIENT_H

#include <afxinet.h>
#include <string>
using namespace std;

#define IE_AGENT _T("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)")

// 操作成功
#define SUCCESS 0
// 操作失败
#define FAILURE 1
// 操作超时
#define OUTTIME 2

class CHttpClient
{
public:
CHttpClient(LPCTSTR strAgent = IE_AGENT);
virtual ~CHttpClient(void);

int HttpGet(LPCTSTR strUrl, LPCTSTR strPostData, string &strResponse);
int HttpPost(LPCTSTR strUrl, LPCTSTR strPostData, string &strResponse);

private:
int ExecuteRequest(LPCTSTR strMethod, LPCTSTR strUrl, LPCTSTR strPostData, string &strResponse);
void Clear();

private:
CInternetSession *m_pSession;
CHttpConnection *m_pConnection;
CHttpFile *m_pFile;
};


以上是在网上找的别人封装好的类,访问没有身份验证的url的时候能够正常获取json数据,但是对于一些需要身份验证的url就访问失败,以下是我的调用代码:
CString strUrl,strPostData;
std::string strResponse;
strUrl=_T("http://gc.ditu.aliyun.com/geocoding?a=苏州市");
int nRet=m_httpClient.HttpPost((LPCTSTR)strUrl,(LPCTSTR)strPostData,strResponse);
...全文
1190 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复

18,356

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 网络编程
c++c语言开发语言 技术论坛(原bbs)
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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