使用 HttpWebResponse 无法获取cookie的解决办法
2005-10-10 09:26
806 查看
排除浏览器等其他因素,只考虑程序的问题,
基本上是因为没在 HttpWebRequest.GetResponse 之前先对 request 的 CookieContainer 实例化
简单代码如下:
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(Url);
myRequest.CookieContainer = new CookieContainer();
HttpWebResponse response = (HttpWebResponse)myRequest.GetResponse();
string _APSNET_SessionValue = response.Cookies["ASP.NET_SessionId"].Value;
如果没在 GetResponse 之前实例化 myRequest.CookieContainer,
访问 response.Cookies , 都是空的。
基本上是因为没在 HttpWebRequest.GetResponse 之前先对 request 的 CookieContainer 实例化
简单代码如下:
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(Url);
myRequest.CookieContainer = new CookieContainer();
HttpWebResponse response = (HttpWebResponse)myRequest.GetResponse();
string _APSNET_SessionValue = response.Cookies["ASP.NET_SessionId"].Value;
如果没在 GetResponse 之前实例化 myRequest.CookieContainer,
访问 response.Cookies , 都是空的。
相关文章推荐
- C# : HttpWebResponse 无法获取cookie的解决办法-
- C# : HttpWebResponse 无法获取cookie的解决办法-
- 解决httpwebrequest无法通过使用代理的局域网获取response的问题
- js_html_input中autocomplete="off"在chrom中失效的解决办法 使用JS模拟锚点跳转 js如何获取url参数 C#模拟httpwebrequest请求_向服务器模拟cookie发送 实习期学到的技术(一) LinqPad的变量比较功能 ASP.NET EF 使用LinqPad 快速学习Linq
- android中HttpClient获取Session然后使用 WebView共享session的解决办法
- android中HttpClient获取Session然后使用 WebView共享session的解决办法(转)
- HttpWebResponse无法准确获取CharacterSet导致网页数据乱码问题的解决
- android中HttpClient获取Session然后使用 WebView共享session的解决办法(转)
- Java代码中使用response.redirect(url)方法,无法获取到中文的解决方法
- .NET 中使用 HttpWebResponse 时 Cookie 的读取
- android WebView使用cmwap无法联网解决办法
- 【转载】HttpWebRequest的GetResponse或GetRequestStream偶尔超时 + 总结各种超时死掉的可能和相应的解决办法
- 无法启动visual studio的localhost web服务器,端口"xxxx"已被使用 解决办法
- 使用Eclipse Jetty插件运行web项目报无法加载WEB-INF/lib下的jar包的解决办法
- Xcode7 HTTP无法获取数据的解决办法(不能用HTTP要用HTTPS的解决办法)
- 使用idea创建web项目后无法创建Java文件夹的问题的解决办法
- asp.net core使用jexus部署在linux无法正确 获取远程ip的解决办法
- webapi集成owin使用Oauth认证时能获取accee_token仍无法登录的解决办法
- HttpWebRequest的GetResponse或GetRequestStream偶尔超时 + 总结各种超时死掉的可能和相应的解决办法
- 【解决方法】iOS9 HTTP 不能正常使用的解决办法(数据无法加载)