我有问题HttpClient
,我一直在HttpRequestException occurred in mscorlib.dll
。我已经从 SVN 下载了以前的工作版本,并且一直收到相同的异常。
为什么我会突然得到这个异常,即使我运行的代码已经运行了好几个星期?
现在我正在尝试使用这个简单的代码进行调试,但是无论我做什么都会遇到同样的异常
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Accept
.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue(
"application/json"));
HttpResponseMessage response
= await client.GetAsync("http://api.themoviedb.org/3/movie/550?api_key=x");
return await response.Content.ReadAsStringAsync();
我的 innerException 如下:
The remote name could not be resolved:
api.themoviedb.org System.Exception System.Net.WebException
我尝试的每个网址都得到相同的结果,它们都在我的浏览器中工作。这是异常和堆栈跟踪:
res "System.Net.Http.HttpRequestException: An error occurred while sending the request.
---> System.Net.WebException: The remote name could not be resolved: 'api.themoviedb.org'
at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResult ar)
--- End of inner exception stack trace ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)