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

vbjohnAsked:
Who is Participating?
 
williamcampbellConnect With a Mentor Commented:
So the code works on your personal machine?

Seems like a permission Problem over the VPN what is the port you are using does it need to opened for VPN access?
0
 
williamcampbellCommented:
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?

0
 
vbjohnAuthor Commented:
I run it on my personal machine and it goes through.  On my VPN (Where we develope) it does not work.
0
 
vbjohnAuthor Commented:
Thank you for your help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.