草庐IT

CookieContainer

全部标签

c# - 如何使用 HttpWebRequest 和 HttpWebResponse 类(Cookie、凭证等)下载文件

谢谢icktoofay,我尝试使用HttpWebRequest和HttpWebResponse。当我通过传递用户名和密码等凭据请求URL时。我将在响应中获取sessionID。获得该sessionID后,如何进一步发展。使用凭据/cookie跟踪经过身份验证的用户。我有要下载的文件的确切Url和凭据。如果您想使用Cookie,我会的。我需要读取文件数据并将其写入/保存在指定位置。我使用的代码是;stringusername="";stringpassword="";stringreqString="https://xxxx.com?FileNAme=asfhasf.mro"+"?"+"

c# - 在 WebClient 中接受 Cookies?

我刚开始尝试使用C#WebClient。我所拥有的是下面的代码,它从网站获取html代码并将其写入.txt文件。我遇到的唯一问题是某些网站要求您在使用该网站之前接受cookie。这导致的不是将真正的网站html代码写入.txt文件,而是写入cookie弹出html代码。代码:stringdownloadedString;System.Net.WebClientclient;client=newSystem.Net.WebClient();//"http://nl.wikipedia.org/wiki/Lijst_van_spelers_van_het_Nederlands_voetba

c# - 在 WebClient 中接受 Cookies?

我刚开始尝试使用C#WebClient。我所拥有的是下面的代码,它从网站获取html代码并将其写入.txt文件。我遇到的唯一问题是某些网站要求您在使用该网站之前接受cookie。这导致的不是将真正的网站html代码写入.txt文件,而是写入cookie弹出html代码。代码:stringdownloadedString;System.Net.WebClientclient;client=newSystem.Net.WebClient();//"http://nl.wikipedia.org/wiki/Lijst_van_spelers_van_het_Nederlands_voetba

c# - HttpClient 不在 CookieContainer 中存储 cookie

我正在使用VS2010+.NET4.0+System.Net.Http(来自Nuget).由于我无法理解的原因,我在HttpResponseMessage中收到的sessioncookie不会自动保存在HttpClientCookieContainer中。这是我的代码的样子:CookieContainercookies=newCookieContainer();HttpClientHandlerhandler=newHttpClientHandler();handler.CookieContainer=cookies;HttpClientclient=newHttpClient(han

c# - HttpClient 不在 CookieContainer 中存储 cookie

我正在使用VS2010+.NET4.0+System.Net.Http(来自Nuget).由于我无法理解的原因,我在HttpResponseMessage中收到的sessioncookie不会自动保存在HttpClientCookieContainer中。这是我的代码的样子:CookieContainercookies=newCookieContainer();HttpClientHandlerhandler=newHttpClientHandler();handler.CookieContainer=cookies;HttpClientclient=newHttpClient(han

c# - 如何获取 CookieContainer 的所有 Cookie?

我想使用Newtonsoft.Json将CookieContainer导出到JSON,但不幸的是CookieContainer没有枚举器或其他东西,所以我无法循环使用它......编辑:使用我发布的解决方案,它会是这样的:privatestaticvoidMain(string[]args){CookieContainercookieContainer=newCookieContainer();cookieContainer.Add(newCookie("name1","value1","/",".testdomain1.com"));cookieContainer.Add(newCo

c# - 如何获取 CookieContainer 的所有 Cookie?

我想使用Newtonsoft.Json将CookieContainer导出到JSON,但不幸的是CookieContainer没有枚举器或其他东西,所以我无法循环使用它......编辑:使用我发布的解决方案,它会是这样的:privatestaticvoidMain(string[]args){CookieContainercookieContainer=newCookieContainer();cookieContainer.Add(newCookie("name1","value1","/",".testdomain1.com"));cookieContainer.Add(newCo

C# - HttpWebRequest POST(登录 Facebook)

我正在尝试在我的程序中登录Facebook并从那里解析一些信息(例如姓名、个人资料照片等)。每次执行下面的代码时,我都会被重定向回Facebook的主页。stringemail="email";stringpw="pw";stringPostData=String.Format("email={0}&pass={1}",email,pw);CookieContainercookieContainer=newCookieContainer();HttpWebRequestreq=(HttpWebRequest)HttpWebRequest.Create("");req.CookieCon

C# - HttpWebRequest POST(登录 Facebook)

我正在尝试在我的程序中登录Facebook并从那里解析一些信息(例如姓名、个人资料照片等)。每次执行下面的代码时,我都会被重定向回Facebook的主页。stringemail="email";stringpw="pw";stringPostData=String.Format("email={0}&pass={1}",email,pw);CookieContainercookieContainer=newCookieContainer();HttpWebRequestreq=(HttpWebRequest)HttpWebRequest.Create("");req.CookieCon

c# - WebClient 使用凭据访问页面

我正在尝试访问同一域/同一asp.net应用程序上的网页,该网页受密码保护。触发此调用的网页和正在访问的网页的凭据相同。这是代码,我不知道为什么我总是以登录表单html代码结束?using(WebClientclient=newWebClient()){client.QueryString.Add("ID","1040");//addparameters//client.Credentials=CredentialCache.DefaultCredentials;//Itriedtoaddcredentialslikethisclient.Credentials=newNetworkC