我这个问题已经超过几天了,这非常令人沮丧。我正在使用在本地服务器和开发服务器上运行的MVC Web API应用程序,但是不幸的是,当我希望将其部署在登台服务器上时,我严重陷入了这一问题。以下是到目前为止我尝试过的代码和选项:
private HttpResponseMessage ExecutePostRequest(string url, string body)
{
try
{
HttpContent Body = new StringContent(body);
Body.Headers.ContentType = new MediaTypeWithQualityHeaderValue("application/json");
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Add("Accept", "application/json");
client.DefaultRequestHeaders.Add("Autorization", "Bearer" + "AccessToken");
HttpResponseMessage response = client.PostAsync(url, Body).Result;
return response;
}
catch (Exception e)
{
WriteLogs(e.ToString(), "Exception");
throw;
}
}
我要传递的URL是一些公共API,例如(https://api.powerbi.com/beta----)
我使用了以下代理设置,但没有任何效果:
<defaultProxy> <proxy usesystemdefault="true" proxyaddress="https://api.powerbi.com" bypassonlocal="True"/> </defaultProxy></system.net>
上面的代码给出了异常,因为“ ServicePointManager不支持https方案的代理。”
我什至检查了我的IE LAN设置。它没有使用任何代理设置。
下面是堆栈跟踪
[SocketException(0x274d):无法建立连接,因为目标计算机主动拒绝了它] System.Net.Sockets.Socket.BeginConnectEx(Endpoint remoteEP,布尔flowContext,AsyncCallback回调,对象状态)+996 System.Net.Sockets.Socket.UnsafeBeginConnect(Endpoint remoteEP,AsyncCallback回调,对象状态)+75 System.Net.ServicePoint.ConnectSocketInternal(布尔值connectFailure,Socket s4,Socket s6,Socket&套接字,IPAddress&地址,ConnectSocketState状态,IAsyncResult asyncResult,Exception&exception)+480
[WebException:无法连接到远程服务器] System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult asyncResult,TransportContext和上下文)+3366493 System.Net.Http.HttpClientHandler.GetRequestStreamCallback(IAsyncResult ar)+155
[HttpRequestException:发送请求时发生错误。]
[AggregateException:发生一个或多个错误。] System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)+5863512 SignalR.Dal.Repositories.DashboardRepository.ExecutePostRequest(字符串url,字符串正文)+475 SignalR.Dal.Repositories.DashboardRepository.GetNominations()+1970 Signal.WebApi.MvcApplication.Application_Start()+359
[HttpException(0x80004005):发生一个或多个错误。] System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext上下文,HttpApplication应用程序)+12600941 System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext,HttpContext上下文,MethodInfo []处理程序)+175 System.Web.HttpApplication.InitSpecial(HttpApplicationState状态,MethodInfo []处理程序,IntPtr appContext,HttpContext上下文)+304 System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext,HttpContext上下文)+404 System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext)+475
[HttpException(0x80004005):发生一个或多个错误。] System.Web.HttpRuntime.FirstRequestInit(HttpContext上下文)+12617988 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext上下文)+159 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr,HttpContext上下文)+12457605