DelegatingHandler 适用于 Localhost 但不适用于 Azure
DelegatingHandler works on Localhost but not on Azure
我有以下代码,在转发到我的 localhost:1671
时工作正常:
protected override async System.Threading.Tasks.Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)
{
UriBuilder forwardUri = new UriBuilder(request.RequestUri);
//remove the proxy port and replace with an Http port
forwardUri.Port = 1671;
//send it on to the requested URL
request.RequestUri = forwardUri.Uri;
HttpClient client = new HttpClient();
if (request.Method == HttpMethod.Get)
request.Content = null;
try
{
var response = await client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead);
if (response.StatusCode == HttpStatusCode.OK)
{
ManageOnline(response.RequestMessage);
}
return response;
}
catch (Exception ex)
{
throw;
}
}
然而,当我将它更改为我在 azure 上的网站时(例如 xxxx.azurewebsites.net),它不起作用。
知道我是否需要对 Azure 进行不同的配置吗?我假设在 Azure 上端口是 80。
我假设您在这里学习本教程:http://blog.kloud.com.au/2013/11/24/do-it-yourself-web-api-proxy/
检查您的 web/app.config
中是否有以下条目
<system.net>
<defaultProxy enabled="false" />
</system.net>
删除 <defaultProxy enabled="false" />
我有以下代码,在转发到我的 localhost:1671
时工作正常:
protected override async System.Threading.Tasks.Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)
{
UriBuilder forwardUri = new UriBuilder(request.RequestUri);
//remove the proxy port and replace with an Http port
forwardUri.Port = 1671;
//send it on to the requested URL
request.RequestUri = forwardUri.Uri;
HttpClient client = new HttpClient();
if (request.Method == HttpMethod.Get)
request.Content = null;
try
{
var response = await client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead);
if (response.StatusCode == HttpStatusCode.OK)
{
ManageOnline(response.RequestMessage);
}
return response;
}
catch (Exception ex)
{
throw;
}
}
然而,当我将它更改为我在 azure 上的网站时(例如 xxxx.azurewebsites.net),它不起作用。
知道我是否需要对 Azure 进行不同的配置吗?我假设在 Azure 上端口是 80。
我假设您在这里学习本教程:http://blog.kloud.com.au/2013/11/24/do-it-yourself-web-api-proxy/
检查您的 web/app.config
中是否有以下条目<system.net>
<defaultProxy enabled="false" />
</system.net>
删除 <defaultProxy enabled="false" />