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

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条)

报告相同问题?

悬赏问题

  • ¥15 铜与钢双金属板叠加在一起每种材料300mm长,18mm宽,4mm厚一端固定并加热至80℃,当加热端温度保持不变时另一端的稳态温度。ansys
  • ¥15 django5安装失败
  • ¥15 Java与Hbase相关问题
  • ¥15 后缀 crn 游戏文件提取资源
  • ¥15 ANSYS分析简单钎焊问题
  • ¥20 bash代码推送不上去 git fetch origin master #失败了
  • ¥15 LOL外服加入了反作弊系统,现在游戏录像rofl文件离线都无法打开
  • ¥15 在centos7安装conda
  • ¥15 c#调用yolo3 dll文件获取的数据对不上
  • ¥20 WPF 如何实现多语言,label 和cs(live Charts)中是否都能翻译