最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C# HttpClient Cookie驗(yàn)證解決方法

 更新時(shí)間:2012年11月29日 10:26:11   作者:  
本文將詳細(xì)介紹C# HttpClient Cookie驗(yàn)證解決方法,需要了解的朋友可以參考下
自實(shí)現(xiàn)的cookie 驗(yàn)證,遠(yuǎn)程取值的例子

以下代碼配合HttpClient使用可以實(shí)現(xiàn)跨域(cookie的讀寫(xiě))
//驗(yàn)證
復(fù)制代碼 代碼如下:

HttpClient httpClient = new HttpClient(url, null, true);
httpClient.PostingData.Add(key,value);//登錄用戶名
httpClient.PostingData.Add(key,value);//密碼
string str = httpClient.GetString();

----寫(xiě)文件 序列化傳回來(lái)的cookie
復(fù)制代碼 代碼如下:

CookieCollection cookies = httpClient.Context.Cookies;//保存一個(gè)全局的cookie文件
FileStream fileStream = new FileStream("xxx.dat", FileMode.Create);
BinaryFormatter b = new BinaryFormatter();
b.Serialize(fileStream, cookies);
fileStream.Close();

--讀文件 反序列化cookies 賦給httpClient的cookies
復(fù)制代碼 代碼如下:

FileStream fileStream = new FileStream("xxx.dat", FileMode.Open, FileAccess.Read, FileShare.Read);
BinaryFormatter b = new BinaryFormatter();
CookieCollection cookies = b.Deserialize(fileStream) as CookieCollection;
HttpClient httpClient = new HttpClient("url");//取值的url
httpClient.Context.Cookies = cookies;
string str = httpClient.GetString();

相關(guān)文章

最新評(píng)論

晋州市| 依安县| 清镇市| 柏乡县| 清镇市| 中阳县| 济南市| 五家渠市| 大宁县| 池州市| 绿春县| 奇台县| 洮南市| 商丘市| 准格尔旗| 商河县| 宁津县| 上蔡县| 湖州市| 荔浦县| 光泽县| 临江市| 富阳市| 珲春市| 长岭县| 于田县| 博乐市| 荣成市| 大安市| 贡嘎县| 丘北县| 南宫市| 十堰市| 财经| 如东县| 乐都县| 绵阳市| 阿拉尔市| 栾城县| 仪征市| 舞钢市|