c# - 无法在路径中找到非法字符

标签 c# string url illegal-characters

我无法在

中找到非法字符

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

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

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

string document = w.DownloadString(url);

这会引发异常:

Argument Exception :Illegal Characters in path

当我直接将其复制到 Chrome 中时,该 URL 工作正常。知道问题出在哪里吗?

最佳答案

我认为问题是因为缺少协议(protocol)(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);

关于c# - 无法在路径中找到非法字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28978966/

相关文章:

python - 将一个应用程序的 url 包含到 django 中另一个应用程序的 urls 文件中

php - 如何将来自不同网站的php页面包含到当前网站?

php - 带有 ñ 或重音符号的友好 Url 问题字符串

c# - 如何从数据 GridView 加载列表<t>

c# - C# 中的递归泛型类型参数

python - 如何在单独的列表中拆分字符串中的每个单词

C 段错误

c# - 如何在桌面应用程序中使用 DbContext 和 DI?

c# - 字符串操作c#

python - 随机化字符串的大小写