VC驿站

 找回密码
 加入驿站

QQ登录

只需一步,快速开始

搜索
查看: 1329|回复: 7

[求助] http协议用post方式发送multipart类型的数据包失败

[复制链接]
81_avatar_middle
在线会员 发表于 2016-3-18 04:55:06 | 显示全部楼层 |阅读模式
27驿站币
这个功能是自动注册的 我模拟post 跟抓包一模一样 可是服务器返回值老是提示用用户名格式不对。 输入验证码和用户名请求服务器时候, 服务器放回来是确定。 但是提交的时候就不行。 哪位高人指点一下
感激不尽
下面是关键代码

CString getSubmitRegContent()
{
        CString content = "";
        CString useNameStr;
        CString usePwdStr;
        CString codeStr;
        CString wefsdfasStr = "黄三";
        CString idcardStr = "14010719890101669x";
        gThis->GetDlgItem(IDC_EDIT_CODE)->GetWindowText(codeStr);
        gThis->GetDlgItem(IDC_EDIT_USER)->GetWindowText(useNameStr);
        gThis->GetDlgItem(IDC_EDIT_PWD)->GetWindowText(usePwdStr);

        CString contentPassLevel;
        contentPassLevel.Format("%s\"passwdlevel\"\r\n\r\n1\r\n", boundary);
        CString contentForward;
        contentForward.Format("%s\"forward\"\r\n\r\n\r\n", boundary);
        CString contentPagefrom;
        contentPagefrom.Format("%s\"pagefrom\"\r\n\r\n105\r\n", boundary);
        CString contentUsername;
        contentUsername.Format("%s\"username\"\r\n\r\n%s\r\n", boundary, useNameStr);
        CString contentUserpwd;
        contentUserpwd.Format("%s\"userpwd\"\r\n\r\n%s\r\n", boundary, usePwdStr);
        CString contentRepwd;
        contentRepwd.Format("%s\"repwd\"\r\n\r\n%s\r\n", boundary, usePwdStr);
        CString contentWefsdfas;
        contentWefsdfas.Format("%s\"wefsdfas\"\r\n\r\n%s\r\n", boundary, wefsdfasStr);
        CString contentIdcard;
        contentIdcard.Format("%s\"idcard\"\r\n\r\n%s\r\n", boundary, idcardStr);
        CString contentCode;
        contentCode.Format("%s\"code\"\r\n\r\n%s\r\n", boundary, codeStr);
        CString contentbutton;
        contentbutton.Format("%s\"button2\"\r\n\r\n\r\n", boundary);
        content = contentPassLevel + contentForward + contentPagefrom + contentUsername + contentUserpwd      \
                + contentRepwd + contentWefsdfas + contentIdcard + contentCode + contentbutton +                   \
                "------WebKitFormBoundaryy4rv3ckfdMboMVzs--\r\n";
        //AfxMessageBox(content);

        return content;
}

UINT submitReg(IWinHttpRequestPtr& pHttpReq)
{
        if (!pHttpReq) return FALSE;

        HRESULT hr = S_FALSE;
        hr = pHttpReq->Open(_T("POST"),_T("URL地址"));
        if (FAILED(hr) || jSessionID == "") return FALSE;
       
        CString codeStr;
        CString useNameStr;
        gThis->GetDlgItem(IDC_EDIT_CODE)->GetWindowText(codeStr);
        gThis->GetDlgItem(IDC_EDIT_USER)->GetWindowText(useNameStr);
        CString cookieStr;
        cookieStr.Format("username_type=0; username=%s; code_type=0; code=%s; ; guanwangvisit=isvisited; %s", useNameStr, codeStr, jSessionID);
        pHttpReq->SetRequestHeader(_T("Content-Type"), _T("multipart/form-data; boundary=----WebKitFormBoundaryy4rv3ckfdMboVNzs"));
        pHttpReq->SetRequestHeader(_T("Accept"), _T("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"));
        pHttpReq->SetRequestHeader(_T("Accept-Language"), _T("zh-CN,zh;q=0.8"));
        pHttpReq->SetRequestHeader(_T("User-Agent"), (LPCTSTR)AGENT_STRING);
        pHttpReq->SetRequestHeader(_T("Host"), _T("passport.aiaigame.com"));
        pHttpReq->SetRequestHeader(_T("Referer"), _T("URL地址"));
        pHttpReq->SetRequestHeader(_T("Connection"), _T("keep-alive"));
        pHttpReq->SetRequestHeader(_T("Cookie"), LPCTSTR(cookieStr));
        //pHttpReq->SetRequestHeader(_T("Content-Length"), LPCTSTR("1042"));
        //pHttpReq->SetRequestHeader(_T("Accept-Encoding"), LPCTSTR("gzip,deflate,sdch"));
        pHttpReq->SetRequestHeader(_T("Cache-Control"), _T("max-age=0"));
        pHttpReq->SetRequestHeader(_T("Origin"), _T("URL地址"));
        CString contentStr = getSubmitRegContent();
        if (contentStr == "")return FALSE;
        hr = pHttpReq->Send(LPCTSTR(contentStr));
        if (FAILED(hr)) return FALSE;
        return TRUE;
}





上一篇:入门级问题
下一篇:为什么会多输出一行
51_avatar_middle
online_admins 发表于 2016-3-18 09:18:14 | 显示全部楼层
感觉还是你的包有问题,没跟浏览器的一直,比如用户名你写的是中文的,所以用不用编码之类的都检查下
81_avatar_middle
ico_lz  楼主| 发表于 2016-3-18 15:26:18 | 显示全部楼层
老大 ,那个中文是身份证名字, 我加上编码也不对http协议用post方式发送multipart类型的数据包失败
81_avatar_middle
ico_lz  楼主| 发表于 2016-3-18 15:29:57 | 显示全部楼层
Syc 发表于 2016-3-18 09:18
感觉还是你的包有问题,没跟浏览器的一直,比如用户名你写的是中文的,所以用不用编码之类的都检查下

这个是我抓的包 POST https://passport.aiaigame.com/passport/reg HTTP/1.1
Host: passport.aiaigame.com
Connection: keep-alive
Content-Length: 1042
Cache-Control: max-age=0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Origin: https://passport.aiaigame.com
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.72 Safari/537.36
Content-Type: multipart/form-data; boundary=----WebKitFormBoundarycAR3gOIyjvOZNdcX
Referer: https://passport.aiaigame.com/passport/reg
Accept-Encoding: gzip,deflate,sdch
Accept-Language: zh-CN,zh;q=0.8
Cookie: username_type=0; username=q2620ld; code_type=0; code=7c38; PHPSESSID=e352e2f0054c409d281406273deccf1f

------WebKitFormBoundarycAR3gOIyjvOZNdcX
Content-Disposition: form-data; name="passwdlevel"

1
------WebKitFormBoundarycAR3gOIyjvOZNdcX
Content-Disposition: form-data; name="forward"


------WebKitFormBoundarycAR3gOIyjvOZNdcX
Content-Disposition: form-data; name="pagefrom"

105
------WebKitFormBoundarycAR3gOIyjvOZNdcX
Content-Disposition: form-data; name="username"

q2620ld
------WebKitFormBoundarycAR3gOIyjvOZNdcX
Content-Disposition: form-data; name="userpwd"

yao815412
------WebKitFormBoundarycAR3gOIyjvOZNdcX
Content-Disposition: form-data; name="repwd"

yao815412
------WebKitFormBoundarycAR3gOIyjvOZNdcX
Content-Disposition: form-data; name="wefsdfas"

要是
------WebKitFormBoundarycAR3gOIyjvOZNdcX
Content-Disposition: form-data; name="idcard"

44082519891004300
------WebKitFormBoundarycAR3gOIyjvOZNdcX
Content-Disposition: form-data; name="code"

7c38
------WebKitFormBoundarycAR3gOIyjvOZNdcX
Content-Disposition: form-data; name="button2"


------WebKitFormBoundarycAR3gOIyjvOZNdcX--
81_avatar_middle
ico_lz  楼主| 发表于 2016-3-18 15:30:43 | 显示全部楼层
yu815412 发表于 2016-3-18 15:29
这个是我抓的包 POST https://passport.aiaigame.com/passport/reg HTTP/1.1
Host: passport.aiaigame.c ...

这个是我模拟post的数据
POST https://passport.aiaigame.com/passport/reg HTTP/1.1
Connection: Keep-Alive
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryy4rv3ckfdMboVNzs
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: zh-CN, en-US
Host: passport.aiaigame.com
Referer: https://passport.aiaigame.com/passport/reg
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.72 Safari/537.36e / 28.0.1500.72 Safari / 537.36
Origin: https ://passport.aiaigame.com
Content-Length: 993
Cookie: username_type=0; username=sdf55555; code_type=0; code=hrpp; ; guanwangvisit=isvisited;  PHPSESSID=8c38273f3a822034c21b38c48f8eb7d6; PHPSESSID=8c38273f3a822034c21b38c48f8eb7d6

------WebKitFormBoundaryy4rv3ckfdMboVNzs
Content - Disposition: form - data; name ="passwdlevel"

1
------WebKitFormBoundaryy4rv3ckfdMboVNzs
Content - Disposition: form - data; name ="forward"


------WebKitFormBoundaryy4rv3ckfdMboVNzs
Content - Disposition: form - data; name ="pagefrom"

105
------WebKitFormBoundaryy4rv3ckfdMboVNzs
Content - Disposition: form - data; name ="username"

sdf55555
------WebKitFormBoundaryy4rv3ckfdMboVNzs
Content - Disposition: form - data; name ="userpwd"

huangyong
------WebKitFormBoundaryy4rv3ckfdMboVNzs
Content - Disposition: form - data; name ="repwd"

huangyong
------WebKitFormBoundaryy4rv3ckfdMboVNzs
Content - Disposition: form - data; name ="wefsdfas"

黄三
------WebKitFormBoundaryy4rv3ckfdMboVNzs
Content - Disposition: form - data; name ="idcard"

14010719890101669x
------WebKitFormBoundaryy4rv3ckfdMboVNzs
Content - Disposition: form - data; name ="button2"


------WebKitFormBoundaryy4rv3ckfdMboVNzs--
51_avatar_middle
online_admins 发表于 2016-3-18 16:05:34 | 显示全部楼层
yu815412 发表于 2016-3-18 15:30
这个是我模拟post的数据
POST https://passport.aiaigame.com/passport/reg HTTP/1.1
Connection: Keep ...

你自己先对比下,看看你的包跟浏览器的有什么不同?
Content - Disposition 跟 Content-Disposition 没看出什么不同吗?
81_avatar_middle
ico_lz  楼主| 发表于 2016-3-18 16:49:55 | 显示全部楼层
Syc 发表于 2016-3-18 16:05
你自己先对比下,看看你的包跟浏览器的有什么不同?
Content - Disposition 跟 Content-Disposition 没 ...

Content-Disposition: form-data; name=    这一行我昨晚改了全部都复制查 找一遍全部相同 还是不行, 我也感觉是包的问题 可是一直找不出哪里的问题,郁闷死了。http协议用post方式发送multipart类型的数据包失败
51_avatar_middle
online_admins 发表于 2016-3-18 16:51:40 | 显示全部楼层
yu815412 发表于 2016-3-18 16:49
Content-Disposition: form-data; name=    这一行我昨晚改了全部都复制查 找一遍全部相同 还是不行, 我 ...

Content - Disposition 跟 Content-Disposition 没看出什么不同吗?
我的意思是:Content - Disposition 两个单词之间有空格,Content-Disposition 原版的是没有空格的,没看出来?
您需要登录后才可以回帖 登录 | 加入驿站 qq_login

本版积分规则

关闭

站长提醒上一条 /2 下一条

QQ|小黑屋|手机版|VC驿站 ( 辽ICP备09019393号tongdun|网站地图wx_jqr

GMT+8, 2019-3-19 06:54

Powered by Discuz! X3.4

© 2009-2019 cctry.com

快速回复 返回顶部 返回列表