Link to home
Start Free TrialLog in
Avatar of vbjohn
vbjohn

asked on

WebRequest - Error - GetRequestStream

System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: 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.

It fails on this line: myRequestStream = myWebRequest.GetRequestStream();


private static string Post(string URL, string Data, ref bool success)
{
string result = "";
success = true;
 
try
{
 
                WebRequest myWebRequest;
                Stream myRequestStream;
                StreamWriter myStreamWriter;
 
                WebResponse myWebResponse;
                Stream myResponseStream;
                StreamReader myStreamReader;
 
                myWebRequest = WebRequest.Create(URL);
                myWebRequest.Timeout = 5000;
 
                {
                    myWebRequest.Method = "POST";
                    myWebRequest.Proxy = null;
                    myWebRequest.ContentType = "application/x-www-form-urlencoded";
                }
                byte[] bytes = Encoding.ASCII.GetBytes(Data);
 
                myWebRequest.ContentLength = bytes.Length;
                myRequestStream = myWebRequest.GetRequestStream();
                myStreamWriter = new StreamWriter(myRequestStream);
                myStreamWriter.Write(Data);
                myStreamWriter.Flush();
                myStreamWriter.Close();
                myRequestStream.Close();
 
                myWebResponse = myWebRequest.GetResponse();
 
                myResponseStream = myWebResponse.GetResponseStream();
                myStreamReader = new StreamReader(myResponseStream);
   
                myStreamReader.Close();
                myResponseStream.Close();
 
                myWebResponse.Close();

Open in new window

Avatar of williamcampbell
williamcampbell
Flag of United States of America image

Looks like a problem on the server end .... can you ping the server?

Can you run that URL in a browser .. see if its valid?

Avatar of vbjohn
vbjohn

ASKER

I run it on my personal machine and it goes through.  On my VPN (Where we develope) it does not work.
ASKER CERTIFIED SOLUTION
Avatar of williamcampbell
williamcampbell
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of vbjohn

ASKER

Thank you for your help.