- IIS 7.5 / Windows Server 2008 R2
- Multiple IIS sites bound to the same IP address, using host names.
- Inbound traffic to sites working fine.
- Outbound web requests made by the back-end site code fail. Remote site returns 404 (NotFound).
- Verified via a network trace that the traffic is making it to the remove server.
- Same requests work fine if done from a site using a dedicated IP address (i.e. not shared w/ any other sites).
Anyone have any ideas on how to make this work or what could be going wrong?
Network trace on hosting server:
Successful request from site w/ non-shared IP address:
No. Time Source Destination Protocol Info
6366 15:54:35.590463 192.168.1.76 173.194.77.121 HTTP GET /key/value/one/two HTTP/1.1
6369 15:54:35.599879 173.194.77.121 192.168.1.76 TCP http > 55407 [ACK] Seq=1 Ack=110 Win=344 Len=0
6370 15:54:35.621587 173.194.77.121 192.168.1.76 HTTP HTTP/1.1 200 OK (application/json)
6608 15:54:35.815774 192.168.1.76 173.194.77.121 TCP 55407 > http [ACK] Seq=110 Ack=357 Win=509 Len=0
Failed request from site using a shared IP address:
No. Time Source Destination Protocol Info
9720 15:54:39.244192 192.168.1.80 173.194.77.121 HTTP GET /key/value/one/two HTTP/1.1
9760 15:54:39.256958 173.194.77.121 192.168.1.80 TCP [TCP segment of a reassembled PDU]
9761 15:54:39.256962 173.194.77.121 192.168.1.80 HTTP HTTP/1.1 404 Not Found (text/html)
9762 15:54:39.257027 192.168.1.80 173.194.77.121 TCP 55438 > http [ACK] Seq=212 Ack=1676 Win=512 Len=0
Code:
public static HttpWebRequest CreateWebRequest(string url, string method = "GET", string referer = null, string contentType = null, int timeout = 100000, string authentication = null, string bindToIpAddress = null, string host = null)
{
var request = (HttpWebRequest)WebRequest.Create(url);
if (!string.IsNullOrWhiteSpace(bindToIpAddress))
{
IPAddress bindIp;
if (!IPAddress.TryParse(bindToIpAddress, out bindIp))
{
throw new ArgumentException("bindToIpAddress");
}
request.ServicePoint.BindIPEndPointDelegate = ((sp, rep, rc) =>
{
return new IPEndPoint(bindIp, 0);
});
}
request.Accept = "*/*";
request.ContentType = contentType;
request.Referer = referer;
request.Method = method;
request.Timeout = timeout;
if (!string.IsNullOrWhiteSpace(host))
{
request.Host = host;
}
return request;
}
string GetData()
{
try
{
string result;
var request = CreateWebRequest("http://ift.tt/1pLXQ3d",
"GET",
"somedomain.com",
timeout: (10 * 1000),
bindToIpAddress: "192.168.27.133" /*site IP*/);
request.Accept = "application/json";
using (var response = request.GetResponse())
{
using (var sr = new StreamReader(response.GetResponseStream()))
{
result = sr.ReadToEnd();
}
}
return result;
}
catch (Exception ex)
{
return null;
}
}
Aucun commentaire:
Enregistrer un commentaire