开发者

reading Cookies in C#

i created php page with these cookies :

setcookie("0","hello+how+are+you",time()+30);

in C# i wrote that code to read cookies :

        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 = (HttpWebRes开发者_运维知识库ponse)httpwr.GetResponse();

        //----Start Getting Cookies----//
        foreach (Cookie cook in httpwrs.Cookies)
        {
            cookiesresult = cook.Value;
        }

        Console.WriteLine("Cookies Recieved : " + cookiesresult);

now cookies value should be : hello+how+are+you but instead value is : hello%2Bhowo%2areo%2you

so it exchanged + with o%2 and i don`t know what is the problem


The cookies are being URL Encoded, also referred to as percent-encoding. Use the HttpServerUtility.UrlDecode method to decode them.


When you create a cookie it turns all special characters into their html equivalent.

For example a google search: http://www.google.com/?q=hello%20there%20how%20are%20you

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜