我有以下代码,可以在转发到我的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。
答案 0 :(得分:1)
我假设您在此处遵循此教程: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" />