I have a strange problem. I have WinForms app that executes a webRequest
var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://*********");
httpWebRequest.ContentType = "application/json";
httpWebRequest.Method = WebRequestMethods.Http.Post;
This works perfectly. I now have a WebForms application that uses exactly the same code. It compiles, but running it results in the following exception:
System.Net.WebException
HResult=0x80131509
Message=Unable to connect to the remote server
Any clues why it would in one and not the other. Its running in a Visual Studio IIS environment (makes no difference if I use IE or Chrome.
Here is the code:
private void GetSession()
{
var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://************");
httpWebRequest.ContentType = "application/json";
httpWebRequest.Method = WebRequestMethods.Http.Post;
using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
{
string json = new JavaScriptSerializer().Serialize(new
{
operation = "****",
username = "****",
password = "****"
});
streamWriter.Write(json);
}
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
JavaScriptSerializer ser = new JavaScriptSerializer();
UserSession =
ser.Deserialize<JsonSession>(new StreamReader(httpResponse.GetResponseStream(), Encoding.Default).ReadToEnd());
}
User contributions licensed under CC BY-SA 3.0