【发布时间】:2019-02-28 19:11:11
【问题描述】:
我附上了以下代码,它在 localhost 中运行良好,但在另一台服务器上的 IIS 中托管时会引发 Web 异常/套接字。
System.Net.Sockets.SocketException (0x80004005):连接尝试失败,因为连接方一段时间后没有正确响应,或者连接失败,因为连接主机没有响应40.113.232.243:443
它在本地也抛出了同样的错误,除非我添加了这一行—— httpWebRequest.Proxy = WebRequest.GetSystemWebProxy();
但它在 iis 服务器中托管时会引发 socketexception。
public async Task<string> Get()
{
try
{
string uri = "https://hp-reporting-*****.azurewebsites.net/********";
var httpWebRequest = (HttpWebRequest)WebRequest.Create(uri);
httpWebRequest.Timeout = 600000;
httpWebRequest.Proxy = WebRequest.GetSystemWebProxy(); // adding this line resolved error in local but still same issue persists when hosted in iis in another server
httpWebRequest.Method = "GET";
HttpWebResponse httpResponse = (HttpWebResponse)await httpWebRequest.GetResponseAsync();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var response = streamReader.ReadToEnd();
// this is your code here...
System.Xml.Linq.XNode node = JsonConvert.DeserializeXNode(response, "Root");
return node.ToString();
}
【问题讨论】:
标签: asp.net-web-api proxy