编程-菜鸟 2015-03-05 03:11 采纳率: 50%
浏览 4150
已采纳

MFC 发送HTTP请求获取Set-Cookie不完全

我想模拟发送Get请求,获取服务器传回的Set-Cookie值,可是获取到的Set-Cookie不完全。
下面是我用火狐的FireDebug抓到的数据:
URL是:

 http://my.37.com/api/login.php?callback=jQuery18301289508974426815_1425523200459&action=login&login_account=dazhewang&password=111111&ajax=0&remember_me=1&save_state=1&ltype=1&_=1425523232168

请求头是:

 GET /api/login.php?callback=jQuery18301289508974426815_1425523200459&action=login&login_account=dazhewang&password=111111&ajax=0&remember_me=1&save_state=1&ltype=1&_=1425523232168 HTTP/1.1
Host: my.37.com
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:36.0) Gecko/20100101 Firefox/36.0
Accept: */*
Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Referer: http://www.37.com/
Connection: keep-alive

响应头信息是:

 HTTP/1.1 200 OK
Server: nginx
Date: Thu, 05 Mar 2015 02:41:55 GMT
Content-Type: text/html; Charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
P3P: CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"
Set-Cookie: PHPSESSID=16414db50d1ca1961594b4b599f4926a; path=/
rt=1; path=/; domain=37.com
passport_37wan_com=204830022%7Cdazhewang%7C1425523315000%7C2cb762f4dcd29cb0df6b1f982568bb8f; expires=Sat, 04-Apr-2015 02:41:55 GMT; path=/; domain=37.com
ispass_37wan_com=89235a5c%7C1%7C3910fa2c75703ed865fba6c86c2fd4db%7C1; expires=Sat, 04-Apr-2015 02:41:55 GMT; path=/; domain=37.com; httponly
37wan_account=dazhewang; expires=Sun, 02-Mar-2025 02:41:55 GMT; path=/; domain=37.com
37loginrefer=LHd3dy4zNy5jb20sLA%3D%3D%7Cc2470b07de2d81a9e1581defa000a0bb; path=/; domain=37.com
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
37web: zs_12_33_web
Content-Encoding: gzip

下面是我的代码:

 CInternetSession session;
    INTERNET_PORT nPort = 80;
    try {
        CHttpConnection* pHttpConnect = session.GetHttpConnection(_T("my.37.com"), nPort);
        if (pHttpConnect) {
            CHttpFile* pFile = pHttpConnect->OpenRequest(CHttpConnection::HTTP_VERB_GET, _T("/api/login.php ?"));  //"/api/login.php ?"的问号应该是不要的吧,我尝试去掉?后,代码结果不变
            if (pFile) {
                pFile->AddRequestHeaders(L"GET /api/login.php ? callback = jQuery18301289508974426815_1425523200459&action = login&login_account = dazhewang&password = 111111 & ajax = 0 & remember_me = 1 & save_state = 1 & ltype = 1 & _ = 1425523232168 HTTP / 1.1"); //这里的参数信息是否是这么添加的?
                pFile->AddRequestHeaders(_T("Accept : */*"));
                pFile->AddRequestHeaders(_T("Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3"));
                pFile->AddRequestHeaders(_T("Referer: http://www.37.com/"));
                pFile->AddRequestHeaders(_T("User-Agent: Mozilla / 5.0 (Windows NT 6.1; WOW64; rv:36.0) Gecko / 20100101 Firefox / 36.0"));
                pFile->AddRequestHeaders(_T("Accept-Encoding: gzip, deflate"));
                pFile->AddRequestHeaders(_T("Host: my.37.com"));
                pFile->AddRequestHeaders(_T("Connection: keep-alive"));
                pFile->AddRequestHeaders(_T("Cache - Control: no - cache"));
                //TCHAR szRequest
                //pFile->SendRequest(NULL, 0, szRequest, MAX_COUNT*sizeof(TCHAR));
                pFile->SendRequest(); //这句代码需要加参数吗?我这里没有要额外添加的信息了
                CString strStatus(_T(""));
                if (pFile->QueryInfo(HTTP_QUERY_RAW_HEADERS_CRLF, strStatus)) {
                    AfxMessageBox(strStatus);
                }   
            }
            pFile->Close();
            delete pFile;
            pFile = NULL;
        }
        return TRUE;
    }
    catch (CInternetException* e)
    {
        e->ReportError();
        e->Delete();
        return FALSE;
    }

返回的响应结果如下:

 HTTP/1.1 200 OK
Server: nginx
Date: Thu, 05 Mar 2015 02:52:49 GMT
Content-Type: text/html; Charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
P3P: CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"
Set-Cookie: PHPSESSID=77363a9a9ab0c6b7bf5c96c80d635e2f; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
37web: gz_82_133_web
Content-Encoding: gzip

Set-Cookie值只1条,请问大神们这是什么原因啊?求解答,万分感谢!!!(由于是新账号,没悬赏分,非常抱歉)

  • 写回答

4条回答 默认 最新

  • oyljerry 2015-03-05 15:12
    关注

    把你代码发的包也抓包,然后跟l浏览器的对比。看缺少什么数据。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页
  • ¥15 376.1电表主站通信协议下发指令全被否认问题
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥15 复杂网络,变滞后传递熵,FDA
  • ¥20 csv格式数据集预处理及模型选择
  • ¥15 部分网页页面无法显示!
  • ¥15 怎样解决power bi 中设置管理聚合,详细信息表和详细信息列显示灰色,而不能选择相应的内容呢?
  • ¥15 QTOF MSE数据分析
  • ¥15 平板录音机录音问题解决
  • ¥15 请问维特智能的安卓APP在手机上存储传感器数据后,如何找到它的存储路径?