title: calling a https api from another web api
body: <p>I am attaching the below piece of code which works perfectly fine in localhost but throws web exception/socket when hosted in IIS on another server.</p>
  
  <p>System.Net.Sockets.SocketException (0x80004005): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 40.113.232.243:443</p>
  
  <p>It was throwing the same error in local too, unless I added this line-
  httpWebRequest.Proxy = WebRequest.GetSystemWebProxy();</p>
  
  <p>yet it throws socketexception when hosted in iis server.</p>
  
  <pre><code>public async Task&lt;string&gt; 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();
              }
  </code></pre>