【问题标题】:.net Uri class does not support URLs longer than 263 characters.net Uri 类不支持长度超过 263 个字符的 URL
【发布时间】:2018-10-17 09:58:22
【问题描述】:

应该支持最多 2000 个字符的 AFAIK。

复制:

var s = "http://www."
+ string.Join("", Enumerable.Repeat("a", 249))
+ ".com";

new Uri(s, UriKind.Absolute);

一个较短的字母正在被解析,没有问题:

var s = "http://www."
+ string.Join("", Enumerable.Repeat("a", 248))
+ ".com";

Uri 类代码起源于 2003 年,并延续到 .net 标准/核心。 MS 是否仍然声称路径/URI 的 255 个字符足以满足每个人的需求?

【问题讨论】:

    标签: .net asp.net-core


    【解决方案1】:

    您正在尝试创建一个 主机名 超过 255 个字符的 Uri。 255 is the max.

    这也反映在异常消息中:

    无效的 URI:无法解析主机名。

    所以这不能怪微软。

    【讨论】:

    • 我打算将“异常消息”一词链接到包含异常消息的this ideone repro,但系统不会让我这样做,因为那样我将不得不重复 OP 的代码。跨度>
    猜你喜欢
    • 1970-01-01
    • 2017-12-28
    • 2019-12-11
    • 1970-01-01
    • 2011-09-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多