我无法在
中找到非法字符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)(http
或 https
)
使用 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/