|
本帖最后由 风度猫 于 2020-2-21 19:08 编辑
长期求助一名萌师傅,我会卖萌会孝敬,可以按咨询频次包月收费.
VC驿站官方的post教程可能5年前的了,之前的例子的网站都关闭了,找老师又发了一个说是类似的,但是中间遇到一个问题,第一步获取cookie的地方就无法获取.我尝试了添加协议头进去,貌似也不行.求大佬解惑.
代码如下
- void CMFCwinhttppostDlg::OnBnClickedOk()
- {
- CoInitialize(NULL);
- IWinHttpRequestPtr P_http = NULL;
- CString H_body, H_name, H_password,H_str;
- _bstr_t H_header;
- K_Edit_name.GetWindowText(H_name);
- K_Edit_passwod.GetWindowText(H_password);
- H_body.Format(_T("u_name=%s&u_password=%s&imageField=登录"), H_name, H_password);
- HRESULT hr = P_http.CreateInstance(__uuidof(WinHttpRequest));
- if (FAILED(hr))return;
- hr = P_http->Open(_T("POST"), _T("http://www.idc816.com/chklogin.asp"));
- if (FAILED(hr))return;
- //P_http->SetRequestHeader(_T("accept"), _T("text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3"));
- //P_http->SetRequestHeader(_T("accept-encoding"), _T("gzip, deflate"));
- //P_http->SetRequestHeader(_T("accept-language"), _T("zh-CN,zh;q=0.9"));
- //P_http->SetRequestHeader(_T("content-type"), _T("application/x-www-form-urlencoded"));
- //P_http->SetRequestHeader(_T("origin"), _T("http://www.idc816.com"));
- //P_http->SetRequestHeader(_T("proxy-authorization"), _T("Basic ZjUwMmRkOTkxZWY3NmYxZTBiNzE2ZDY3NDFlZWI4YWI6ZGFqaW4xMjM="));
- P_http->SetRequestHeader(_T("referer"), _T("http://www.idc816.com/default.asp"));
- //P_http->SetRequestHeader(_T("upgrade-insecure-requests"), _T("1"));
- P_http->SetRequestHeader(_T("user-agent"), _T("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36"));
- COleVariant body_srt;
- body_srt = H_body;
- hr = P_http->Send(body_srt);
- if (FAILED(hr))return;
- long H_Status=P_http->Status;
- H_str.Format(_T("返回status值:%d\n"), H_Status);
- OutputDebugString(H_str);
- H_header = P_http->GetAllResponseHeaders();
- OutputDebugString(H_header);
- CoUninitialize();
- CDialog::OnOK();
- }
复制代码
源代码文件
MFC_winhttp_post.zip
(131.94 KB, 下载次数: 5)
|
上一篇: 对话框扩展操作问题下一篇: c++的mfcd达成的效果
|