发送请求时发生错误。 [英] An error occurred while sending the request.
问题描述
当我打电话给 HttpClient服务和应用程序转到后台 (停用)当我去激活它时抛出这个execption
{System.Net.WebException:抛出了类型'System.Net.WebException'的异常。 ---> System.Net.WebException:抛出了类型'System.Net.WebException'的异常。
在System.Net.Browser.ClientHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
在System.Net.Browser.ClientHttpWebRequest。<> c__DisplayClasse。< EndGetResponse> b__d(Object sendState)
在System.Net.Browser.AsyncHelper。<> c__DisplayClass1。< BeginOnUI> b__0(Object sendState)
---内部异常堆栈跟踪结束---
在System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod,Object state)
在System.Net.Browser.ClientHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
在System.Net.Http.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
在System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResult ar)}
DesertQueen
你好DevWP,
>>当我打电话给 HttpClient服务和应用程序转到后台 (停用)当我去激活它时抛出execption
如果你可以尝试在这里发布你的代码会更好。
然后我创建了以下WCF休息服务:
[ServiceContract]
公共接口IMyService1
{
[OperationContract]
[WebGet(UriTemplate =" GetMyData")]
string GetData();
}
之后我可以在HttpClient类的帮助下调用上面的WCF Rest服务:
private async void CallHttpClientService()
{
HttpClient httpClient = new HttpClient();
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get," http://*******/MyService1.svc/GetMyData");
HttpResponseMessage response = await httpClient.SendAsync(request);
string result = await response.Content.ReadAsStringAsync();
var MessageDialog = new MessageDialog(result);
等待MessageDialog.ShowAsync();
}它运作正常。
最好的问候,
Amy Peng
When i call HttpClient service and application go to background (deactivated) when i go to activate it throw this execption
{System.Net.WebException: Exception of type 'System.Net.WebException' was thrown. ---> System.Net.WebException: Exception of type 'System.Net.WebException' was thrown.
at System.Net.Browser.ClientHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
at System.Net.Browser.ClientHttpWebRequest.<>c__DisplayClasse.<EndGetResponse>b__d(Object sendState)
at System.Net.Browser.AsyncHelper.<>c__DisplayClass1.<BeginOnUI>b__0(Object sendState)
--- End of inner exception stack trace ---
at System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state)
at System.Net.Browser.ClientHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.Net.Http.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResult ar)}
DesertQueen
Hi DevWP,
>>When i call HttpClient service and application go to background (deactivated) when i go to activate it throw execptionIt will be better if you can try to post your code here.
Then I have created the following WCF Rest Service:
[ServiceContract] public interface IMyService1 { [OperationContract] [WebGet(UriTemplate = "GetMyData")] string GetData(); }
After that I can call the above WCF Rest Service with the help of the HttpClient class:
private async void CallHttpClientService() { HttpClient httpClient = new HttpClient(); HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://*******/MyService1.svc/GetMyData"); HttpResponseMessage response = await httpClient.SendAsync(request); string result = await response.Content.ReadAsStringAsync(); var MessageDialog = new MessageDialog(result ); await MessageDialog.ShowAsync(); }It just works fine.
Best Regards,
Amy Peng
这篇关于发送请求时发生错误。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!