string url_Login_Group = "http://ui.ptlogin2.qq.com/cgi-bin/login?appid=549000912&daid=5&style=12&s_url=http%3A%2F%2Fqun.qzone.qq.com%2Fgroup%23!%2F336100817%2Fmember";
string WebCode = GetWebString(url_Login_Group);
//获取Cookie值
//string qrsig = Cookies.GetCookies(new Uri("http://ptlogin2.qq.com"))["qrsig"].Value;
//获取Cookie值
string uikey = Cookies.GetCookies(new Uri("https://xui.ptlogin2.qq.com"))["uikey"].Value;
Console.WriteLine(uikey);
Console.WriteLine(WebCode);
Console.ReadLine();
public static CookieContainer Cookies = new CookieContainer();
public static string GetWebString(string url, string referer = null, Encoding encode = null)
{
string webdat = null;
HttpWebRequest req = null;
HttpWebResponse res = null;
try
{
req = (HttpWebRequest)WebRequest.Create(url);
req.CookieContainer = Cookies;
req.AllowAutoRedirect = false;
req.Timeout = ;
req.Referer = referer;
req.Proxy = null;
req.UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36";
res = (HttpWebResponse)req.GetResponse();
Cookies.Add(res.Cookies);
using (StreamReader reader = new StreamReader(res.GetResponseStream(), encode == null ? Encoding.UTF8 : encode))
{
webdat = reader.ReadToEnd();
}
//using (FileStream fs = new FileStream("webdat.txt", FileMode.Create))
//{
// byte[] data = Encoding.UTF8.GetBytes(webdat);
// fs.Write(data, 0, data.Length);
//}
}
catch (HttpException httpex)
{
return "HttpException:" + httpex + "";
}
catch (WebException webex)
{
return "WebException:" + webex + "";
}
finally
{
if (res != null)
{
res.Close();
}
if (req != null)
{
req.Abort();
}
}
return webdat;
}

取Cookie值的更多相关文章

  1. Vuex 页面刷新后store保存的数据会丢失 取cookie值

    在store.js中 export default new vuex.Store({ // 首先声明一个状态 state state:{ pcid: '', postList: [], } //更新状 ...

  2. PHP curl爬取数据 加入cookie值

    public function get_cookie(){ header("Content-type:text/html;Charset=utf8"); $ch =curl_ini ...

  3. JS存取Cookie值

    一:存Cookie //存Cookie document.cookie = "id=" + escape(value); 二:取Cookie //提取Cookie值 functio ...

  4. C# .net中cookie值为中文时的乱码解决方法

    一.cookie的名称或子cookie的名称不能为中文,否则无法获得cookie 这个好办,名称不用中文即可 二.cookie的值为中文时候,取cookie的值会出现乱码 解决办法:存取cookie时 ...

  5. webBrowser获取取Cookie不全的解决方法

    //取当前webBrowser登录后的Cookie值           [DllImport("wininet.dll", CharSet = CharSet.Auto, Set ...

  6. httpclient 怎么带上登录成功后返回的cookie值访问下一页面

    我是只很菜很菜的小鸟.刚上班,有这个一个需求.要我抓取别的网站的数据.     我根据用户密码登录一个网站成功后,生成一个cookie值.我已经获取到了.然后要带上这个cookie值进行下一页面的访问 ...

  7. 在webBrowser中取Cookie的方法

    在很多情况下我们会使用间进程的webBrowser去实现一些网页的请求和抓去,这个时候有部分网页是取不到Cookie的,那怎么办呢?下面我提供一个方法,应该99%的都能取到, //取当前webBrow ...

  8. JS获取指定的cookie值

    cookie Name为TEST_COOKIE:用如下方法可以获取cookie值: document.cookie.replace(/(?:(?:^|.*;\s*)TEST_COOKIE\s*\=\s ...

  9. php取默认值以及类的继承

    (1)对于php的默认值的使用和C++有点类似,都是在函数的输入中填写默认值,以下是php方法中对于默认值的应用: <?phpfunction makecoffee($types = array ...

随机推荐

  1. remote: error: hook declined to update refs/heads

    打开工程目录下.git/config文件,补充user信息 , [user] username = xxx email = xxx@126.com 打开工程目录下.git/description文件, ...

  2. CCF_201512-1_数位之和

    水. #include<iostream> #include<cstdio> using namespace std; int main() { ; cin >> ...

  3. mysql添加远程权限

    mysql -u root -p grant all privileges on *.* to root@'%' identified by "password"; flush p ...

  4. 20200120--python学习第12天

    今日内容 函数中高级(闭包/高价函数) 内置函数 内置模块(.py文件) 内容回顾 函数基础概念 a.函数基本结构 def func(arg): return arg v1 = func(123) b ...

  5. 学习CSS之如何改变CSS伪元素的样式

    一.CSS伪元素 CSS 伪元素用于向某些选择器设置特殊效果. 伪元素的用法如下: selector:pseudo-element {property:value;} CSS 类也可以和伪元素搭配使用 ...

  6. Windwos日志分析

    Windows日志分析工具 查看系统日志方法: 在“开始”菜单上,依次指向“所有程序”.“管理工具”,然后单击“事件查看器” 按 "Window+R",输入 ”eventvwr.m ...

  7. js模拟post提交表单

    function post(URL, PARAMS) {            var temp = document.createElement("form");         ...

  8. bootstrap-daterangepicker

    1,依赖关系 使用之前需要引用bootstrap.css   daterangpicker.css    jquery.js   boostrap.js  moment.js   daterangpi ...

  9. iOS开发 - 在SwiftUI中显示模态视图

    在SwiftUI中显示模态视图 简介 这里教大家如何弹出一个简单的模态视图.分别有两个页面,ContentView和GCPresentedView,以下对应简称为A和B.我们要做的是在A视图中点击按钮 ...

  10. MySQL - SQL语句优化方法

    1.使用 show status 了解各种 SQL 的执行频率 mysql> show status like 'Com%'; 该命令可以查询 sql 命令的执行次数. 2.定位执行效率较低的 ...