I am having problems connecting to any remote server when my web application is published to IIS, I don't have these problems when running the web app from Visual Studio. I am connecting to the remote server using HTTPWebRequest. I wrote a snippet of code to just test getting a screen scape from google. Again, the screen scrape works fine when running to from VS, but not from iiS.
The error I receive is:
[SocketException (0x2726): An invalid argument was supplied]
System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) +1001890
System.Net.Sockets.Socket.InternalConnect(EndPoint remoteEP) +33
System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception) +431
[WebException: Unable to connect to the remote server]
System.Net.HttpWebRequest.GetResponse() +1501755
_Default.Page_Load(Object sender, EventArgs e) +61
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +34
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061
HERE IS THE CODE:
protected void Page_Load(object sender, EventArgs e)
{
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://www.google.com");
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
StreamReader sr = new StreamReader(resp.GetResponseStream());
string google = sr.ReadToEnd();
sr.Close();
Response.Write(google + "<br>");
}