VC驿站

 找回密码
 加入驿站

QQ登录

只需一步,快速开始

搜索
查看: 961|回复: 3

[求助] post 如何 带cookier 发送

[复制链接]
47_avatar_middle
在线会员 发表于 2017-5-21 22:55:18 | 显示全部楼层 |阅读模式
3驿站币
   我需要post 登陆,但是有cookier  ,我用  InternetSetCookie 设置cookier 但是会把cookier 截断,比如cookier 是 abc;efisdfew;osssseeee;00jj   类似这样 的,中间有 ; 的,用InternetSetCookie设置后
发现发送的cookier 只有 abc 了,后面的都没有了,怎么回事





上一篇:怎么打开一个程序向他发送点击消息
下一篇:如何个程序添加网络验证
49_avatar_middle
在线会员 发表于 2017-5-22 09:04:44 | 显示全部楼层
Python很简单的
05_avatar_middle
在线会员 发表于 2017-5-22 10:41:48 | 显示全部楼层
string Web_Visit(string  url, int mode, string data_c, string setcookie)
{
        string Str_url = url;
        char * data = (char*)data_c.c_str();
        bool https;
        char *VisitMode;
        char *user_Agent;
        int RequestSign;
        string Domain = GetDomain(url);
        string  header = "Accept: */*\nReferer:" + Str_url + "\nAccept-Language: zh-cn\nContent-Type: application/x-www-form-urlencoded";
        if ("" != setcookie)
        {
                header = header + "\nCookie: " + setcookie;
        }



        char *Cdomain = (char*)Domain.c_str();
        if (0 == mode)
        {
                VisitMode = "GET";
        }
        else if (1 == mode)
        {
                VisitMode = "POST";
        }
        else
        {
                VisitMode = "GET";
        }
        if ("https" == Str_url.substr(0, 5))
        {
                https = true;
        }
        else
        {
                https = false;
        }


        user_Agent = "Mozilla / 4.0 (compatible; MSIE 9.0; Windows NT 6.1)";
        HINTERNET hInternet = InternetOpenA(user_Agent, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0); //初始化WinINet
        if (NULL == hInternet)
        {
                InternetCloseHandle(hInternet);
                return "";
        }
        HINTERNET hConnect;
        if (https)
        {
                hConnect = InternetConnectA(hInternet, Cdomain, INTERNET_DEFAULT_HTTPS_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0); //连接服务器
        }
        else
        {
                hConnect = InternetConnectA(hInternet, Cdomain, INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0); //连接服务器
        }

        if (NULL == hConnect)
        {
                InternetCloseHandle(hConnect);
                return "";
        }


        RequestSign = INTERNET_FLAG_RELOAD | INTERNET_COOKIE_THIRD_PARTY;
        if ("" != setcookie)
        {
                RequestSign = RequestSign | INTERNET_FLAG_NO_COOKIES;
        }

        if (https)
        {

                RequestSign = RequestSign | INTERNET_FLAG_SECURE;
        }
        else
        {
                RequestSign = RequestSign | INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS;
        }

        string pageadd = GetPageAdd(url);
        char *Cpageadd = (char*)pageadd.c_str();
        HINTERNET hOpenRequest = HttpOpenRequestA(hConnect, VisitMode, Cpageadd, "HTTP / 1.1", NULL, NULL, RequestSign, 0); //创建http请求
        if (NULL == hOpenRequest)
        {
                InternetCloseHandle(hOpenRequest);
                InternetCloseHandle(hConnect);
                InternetCloseHandle(hInternet);
                return "";
        }
        if (0 == mode)
        {
                char * Cheader = (char*)header.c_str();
                //BOOL bRequest = HttpSendRequestA(hOpenRequest, header, (DWORD)strlen(header), NULL, (DWORD)0); //发送http请求
                BOOL bRequest = HttpSendRequestA(hOpenRequest, Cheader, (DWORD)strlen(Cheader), NULL, (DWORD)0);
        }
        else if (1 == mode)
        {
                char * Cheader = (char*)header.c_str();
                BOOL bRequest = HttpSendRequestA(hOpenRequest, Cheader, (DWORD)strlen(Cheader), data, (DWORD)strlen(data)); //发送http请求
        }

        char szBuffer[1024];
        ZeroMemory(szBuffer, 1024);
        char b[1024];
        ZeroMemory(b, 1024);
        DWORD dwByteRead = 0;
        string buf;
        /*
        FILE* fp = NULL;
        fopen_s(&fp, "1.txt", "w");*/
        while (InternetReadFile(hOpenRequest, szBuffer, 1024, &dwByteRead) && dwByteRead > 0)
        {

                memcpy(b, szBuffer, dwByteRead);
                buf = buf + b;
                //fwrite(szBuffer, dwByteRead, 1, fp);
                ZeroMemory(szBuffer, 1024);
                ZeroMemory(b, 1024);
        }
        //fclose(fp);
        char backhead[5000];
        ZeroMemory(backhead, 5000);
        DWORD LEN = sizeof(backhead);
        HttpQueryInfoA(hOpenRequest, HTTP_QUERY_RAW_HEADERS_CRLF, backhead, &LEN, 0);
        InternetCloseHandle(hOpenRequest);
        InternetCloseHandle(hConnect);
        InternetCloseHandle(hInternet);
        return buf;
}
47_avatar_middle
ico_lz  楼主| 发表于 2017-5-22 17:51:40 | 显示全部楼层
知道原因了,我头写错了,post 成功了,200状态对了,但是返回的信息获取不全 ,完整的是


HTTP/1.1 200 OK
Date: Mon, 22 May 2017 09:41:40 GMT
Server: Microsoft-IIS/6.0
Cache-Control: Must-revalidate
X-Powered-By: PHP/5.2.17
Set-Cookie: Vguy_2132_sid=aaK4fK; expires=Tue, 23-May-2017 09:41:40 GMT; path=/
Set-Cookie: Vguy_2132_lastact=1495446100%09member.php%09logging; expires=Tue, 23-May-2017 09:41:40 GMT; path=/
Set-Cookie: Vguy_2132_sid=aaK4fK; expires=Tue, 23-May-2017 09:41:40 GMT; path=/
Set-Cookie: Vguy_2132_auth=09f2A5iAPdAsnx6c%2BEzS%2BvEmPtPJq00%2FrjMUwekY%2FEr4BGHLY4Ibx5k62seKp7jZNj3h%2BNB9fp%2Br1UMhDDsgjClJtw; path=/; httponly
Set-Cookie: Vguy_2132_loginuser=deleted; expires=Sun, 22-May-2016 09:41:39 GMT; path=/
Set-Cookie: Vguy_2132_activationauth=deleted; expires=Sun, 22-May-2016 09:41:39 GMT; path=/
Set-Cookie: Vguy_2132_pmnum=deleted; expires=Sun, 22-May-2016 09:41:39 GMT; path=/
Set-Cookie: Vguy_2132_lastcheckfeed=10247%7C1495446100; expires=Tue, 22-May-2018 09:41:40 GMT; path=/
Set-Cookie: Vguy_2132_checkfollow=1; expires=Mon, 22-May-2017 09:42:10 GMT; path=/
Set-Cookie: Vguy_2132_security_cookiereport=548e7Or1Gt2Lwon4KZDI7vKPNZJ0XNhL1ugf2DjsfxDuIvoB1Xdv; expires=Mon, 22-May-2017 21:41:40 GMT; path=/
Expires: -1
Cache-Control: no-store, private, post-check=0, pre-check=0, max-age=0

Pragma: no-cache
Content-type: text/xml; charset=gbk
Content-Length: 158

<?xml version="1.0" encoding="gbk"?>
<root><![CDATA[<script type="text/javascript" reload="1">window.location.href='http://www.aaa.bbb';</script>]]></root>


这是完整的,但是   InternetReadFile 读取的是  

<?xml version="1.0" encoding="gbk"?>
<root><![CDATA[<script type="text/javascript" reload="1">window.location.href='http://www.aaa.bbb';</script>]]></root>

这一段,循环读也是这个  什么意思的
您需要登录后才可以回帖 登录 | 加入驿站 qq_login

本版积分规则

关闭

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

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

GMT+8, 2019-5-20 09:40

Powered by Discuz! X3.4

© 2009-2019 cctry.com

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