【发布时间】:2015-05-19 04:32:58
【问题描述】:
我使用的 URL 在我将其放入 chrome 时有效,但在我的 VS C# 代码中使用相同的 URL(公共异步静态任务)
using (var client = new HttpClient(handler)) {
client.BaseAddress = new Uri(url); ----------> Error
....
Method threw exception:
System.AggregateException: One or more errors occurred. ---> System.UriFormatException: Invalid URI: The URI is empty.
Result StackTrace:
at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
at System.Uri..ctor(String uriString)
我确定 URL 没有格式错误,所以我无法弄清楚这个错误的原因可能是什么。感谢您的帮助。
【问题讨论】:
-
请在您的问题中添加网址
-
确保您在 url(http 或 https)中包含协议 - 没有它,Uri 创建将失败。
-
@Novak007 在调试时,你看到
url变量包含你所期望的吗?我怀疑它里面有空字符串。 -
@Novak007 你真的在调试你的代码吗?你应该这样做,这样你就不会误导人们。我认为发布您的实际代码可能会有所帮助
标签: c# .net visual-studio visual-studio-2013