c# - 如何创建以点为前缀的 cookie uri?

标签 c# .net cookies httpwebrequest uri

我正在尝试传递 new Uri(".example.com")

的 Uri

Invalid URI: The format of the URI could not be determined.

new Uri("http://.example.com")

Invalid URI: The hostname could not be parsed.

我需要能够使用 CookieContainer.SetCookies 函数,它只有一个采用 Uri 的重载。

根据 this page , .NET 4.0 现在应该支持点前缀的 cookie,但是 Uri 类似乎不支持?

最佳答案

在这种情况下,您需要将正确的 uri 传递给函数,并且 Uri 解析器会正确拒绝您尝试使用的格式错误的字符串。

我建议使用 Cookie采用 4 个参数的构造函数 - 允许您将域设置为以点为前缀的域。

Cookie(string name, string value, string path, string domain);

关于c# - 如何创建以点为前缀的 cookie uri?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11427000/

相关文章:

c# - NHibernate 不尊重创建数字列(对于小数)的精度和比例

c# - 在 C# 中,我如何停止执行来自其绑定(bind)委托(delegate)之一的事件?

c# - 更新数据绑定(bind)组合框

java - 来自响应的 Internet Explorer Cookie 不会覆盖现有 Cookie

php - 将cookie 设置为空值不起作用

c# - Entity Framework 连接到 Oracle : ODP for . NET "does not support time"

c# - 如何从数据库 SQL 添加组合框值

c# - 修复 TableLayoutPanel 中每一行的行高

c# - .NET:在验证/读取 XML 模式时阻止 Web 访问?

Javascript object.value 返回未定义