C# 用C语言阅读Cookies#
我用这些cookies创建了php页面:C# 用C语言阅读Cookies#,c#,php,cookies,C#,Php,Cookies,我用这些cookies创建了php页面: setcookie("0","hello+how+are+you",time()+30); string webaddr = "http://www.mywebsite.com"; string cookiesresult = ""; //----Establish Connection to web and get cookies [Commands]----// HttpWebReq
setcookie("0","hello+how+are+you",time()+30);
string webaddr = "http://www.mywebsite.com";
string cookiesresult = "";
//----Establish Connection to web and get cookies [Commands]----//
HttpWebRequest httpwr = (HttpWebRequest)WebRequest.Create(webaddr);
httpwr.CookieContainer = new CookieContainer();
HttpWebResponse httpwrs = (HttpWebResponse)httpwr.GetResponse();
//----Start Getting Cookies----//
foreach (Cookie cook in httpwrs.Cookies)
{
cookiesresult = cook.Value;
}
Console.WriteLine("Cookies Recieved : " + cookiesresult);
在C#中,我编写了读取cookies的代码:
setcookie("0","hello+how+are+you",time()+30);
string webaddr = "http://www.mywebsite.com";
string cookiesresult = "";
//----Establish Connection to web and get cookies [Commands]----//
HttpWebRequest httpwr = (HttpWebRequest)WebRequest.Create(webaddr);
httpwr.CookieContainer = new CookieContainer();
HttpWebResponse httpwrs = (HttpWebResponse)httpwr.GetResponse();
//----Start Getting Cookies----//
foreach (Cookie cook in httpwrs.Cookies)
{
cookiesresult = cook.Value;
}
Console.WriteLine("Cookies Recieved : " + cookiesresult);
现在cookies的值应该是:hello+how+you
但实际值是:hello%2Howo%2areo%2you
因此,它与o%2交换了+,我不知道问题出在哪里当您创建cookie时,它会将所有特殊字符转换为它们的html等价物
例如,谷歌搜索:当您创建cookie时,它会将所有特殊字符转换为它们的html等价物
例如,谷歌搜索:正在对cookies进行编码,也称为百分比编码。使用该方法对其进行解码。正在对cookie进行编码,也称为百分比编码。使用该方法对它们进行解码。它应该将
+
替换为%2B
。它应该将+
替换为%2B
。只是为了澄清:OP示例中的:%2B是“+”,而您示例中的%20是空格。我使用的是.net framework 2,所以我使用系统。什么?要获取HttpServerUtility??thanksIt在.NETFramework2.0中受支持。它位于名称空间System.Web中,在System.Web.dlli中,库出现问题,现在我写了一个程序来读取cookies,一些cookies正在被编码,所以我需要对它们进行解码,我知道我必须使用library System.Web.HttpUtility.UrlEncode来解码cookies,但是每当我使用System.Web.HttpUtility.UrlEncode键入cookies时,我没有得到任何库,它只是停止使用System.Web;没有更多,没有网络的子。我正在使用.NETFrame2,我在.NETFramework4上试过,但没有成功。我不使用ASP,而是使用控制台应用程序。我找到了HttpServerUtility.UrlTokenDecode,但无法使用it@BOSS-添加System.Web.dll
作为项目的参考。使用System.Web添加代码>到类的顶部。使用代码中的方法HttpUtility.UrlDecode()
对cookie的值进行解码。我使用的是.net framework 2,所以我使用的是system。什么?要获取HttpServerUtility??thanksIt在.NETFramework2.0中受支持。它位于名称空间System.Web中,在System.Web.dlli中,库出现问题,现在我写了一个程序来读取cookies,一些cookies正在被编码,所以我需要对它们进行解码,我知道我必须使用library System.Web.HttpUtility.UrlEncode来解码cookies,但是每当我使用System.Web.HttpUtility.UrlEncode键入cookies时,我没有得到任何库,它只是停止使用System.Web;没有更多,没有网络的子。我正在使用.NETFrame2,我在.NETFramework4上试过,但没有成功。我不使用ASP,而是使用控制台应用程序。我找到了HttpServerUtility.UrlTokenDecode,但无法使用it@BOSS-添加System.Web.dll
作为项目的参考。使用System.Web添加代码>到类的顶部。在代码中使用方法HttpUtility.UrlDecode()
,对cookie的值进行解码。