【问题标题】:Unable to find illegal Characters in Path无法在路径中找到非法字符
【发布时间】:2015-05-12 18:58:54
【问题描述】:

我在

中找不到非法字符

www.rightmove.co.uk/propertyMedia/redirect.html?propertyId=47772832&contentId=778055923&index=0

这是我从调试器中获取的 URL。

我在WebClient这个方法中使用了上面的URL

string document = w.DownloadString(url);

这会引发异常:

参数异常:路径中的非法字符

当我将 URL 直接复制到 Chrome 中时,它可以正常工作。知道可能是什么问题吗?

【问题讨论】:

  • 是否包含协议(http 或 https)?
  • 抛出什么类型的异常?一个“WebException”?如果您阅读this,您会发现您需要一个以“http://”等协议开头的正确网址。
  • @QualityCatalyst 参数异常
  • 请试试这个,会发生什么? url = "http:// www.rightmove.co.uk/propertyMedia/redirect.html?propertyId=47772832&contentId=778055923&index=0";.
  • @QualityCatalyst 同样的异常 :(

标签: c# string url illegal-characters


【解决方案1】:

我认为问题是因为缺少协议(httphttps

使用Uri.IsWellFormedUriString 检查Uri 是否有效。

错误:

Uri.IsWellFormedUriString("www.rightmove.co.uk/propertyMedia/redirect.html?propertyId=47772832&contentId=778055923&index=0",UriKind.Absolute);

正确:

Uri.IsWellFormedUriString("http://www.rightmove.co.uk/propertyMedia/redirect.html?propertyId=47772832&contentId=778055923&index=0",UriKind.Absolute);

【讨论】:

    猜你喜欢
    • 2019-08-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-05
    • 2018-02-28
    • 2015-07-31
    相关资源
    最近更新 更多