WebRequest - Error - GetRequestStream

Posted on 2009-04-16
Last Modified: 2012-05-06
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;




                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);





                myWebResponse = myWebRequest.GetResponse();

                myResponseStream = myWebResponse.GetResponseStream();

                myStreamReader = new StreamReader(myResponseStream);





Open in new window

Question by:vbjohn
    LVL 12

    Expert Comment

    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?


    Author Comment

    I run it on my personal machine and it goes through.  On my VPN (Where we develope) it does not work.
    LVL 12

    Accepted Solution

    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?

    Author Closing Comment

    Thank you for your help.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now