Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

WebRequest - Error - GetRequestStream

Posted on 2009-04-16
4
Medium Priority
?
861 Views
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;
 
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

0
Comment
Question by:vbjohn
  • 2
  • 2
4 Comments
 
LVL 12

Expert Comment

by:williamcampbell
ID: 24162739
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
 

Author Comment

by:vbjohn
ID: 24162751
I run it on my personal machine and it goes through.  On my VPN (Where we develope) it does not work.
0
 
LVL 12

Accepted Solution

by:
williamcampbell earned 500 total points
ID: 24162948
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
 

Author Closing Comment

by:vbjohn
ID: 31571185
Thank you for your help.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month21 days, 1 hour left to enroll

810 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