我正在尝试传递 new Uri(".example.com")
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/