【问题标题】:Exception calling Add. Part of cookie is invalid异常调用添加。部分cookie无效
【发布时间】:2013-12-12 02:21:56
【问题描述】:

我正在使用System.Net.CookieContainerAdd 方法。多年来它一直运作良好,但突然间我得到:

使用“2”个参数调用“Add”的异常:“The '价值'='321,386,%2F%3Fa%3D1,http%3A%2F%2Fwww.xxxx.com%2Fpremium%2Fmoney' 部分 cookie 无效。”

我正在添加从网页返回的 cookie。网页的原始标题是:

...
_chartbeat_uuniq=1;
_chartbeat5=321,386,%2F%3Fa%3D1,http%3A%2F%2Fwww.xxx.com%2Fpremium%2Fmoney;
gs_p_GSN-375009-Z=0;
...

cookie 值有什么问题?是逗号吗?

【问题讨论】:

    标签: c# .net httpcookie


    【解决方案1】:

    您应该对 cookie 值进行编码。最好的方法是使用UrlEncodeCheck this out.

    HttpServerUtility.UrlEncode
    

    【讨论】:

    • 我是这么想的,但是 cookie 值看起来已经是 Url 编码的了。
    • 也许你应该对你拥有的东西进行 UrlDecode 然后再次编码
    • 我打开了Fiddler2,发现IE和Chrome对逗号还是挺满意的。只有 CookieContainer 类会犹豫。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-24
    • 2011-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多