954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

The underlying connection was closed: An unexpected error occurred on a receive.

I am trying to do a httpwebrequest with a proxy and everytime I try to do it I get this error:

The underlying connection was closed: An unexpected error occurred on a receive.
kytro360
Light Poster
37 posts since Aug 2011
Reputation Points: 9
Solved Threads: 0
 

Would it be possible for you to show the code you are using? It's hard to debug code without actually seeing it.

Momerath
Nearly a Senior Poster
3,384 posts since Aug 2010
Reputation Points: 1,232
Solved Threads: 558
 

I could show the code but Im removing the postdata of the request and the site that I am httpwebrequesting to since I am planning to sell the software and dont want leechers to get their hands on it. Hope you understand.

string MyProxyHostString = txtBoxIP.Text;
int MyProxyPort = System.Convert.ToInt32(txtBoxPort.Text);

System.Net.ServicePointManager.Expect100Continue = false;

string postdata = "";


 UTF8Encoding encoding1 = new UTF8Encoding();
byte[] bytedata = encoding1.GetBytes(postdata);

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("");
 request.Proxy = new WebProxy(MyProxyHostString, MyProxyPort);
request.Method = "POST";
request.KeepAlive = false;
request.ContentType = "application/x-www-form-urlencoded";
request.Referer = "";
request.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6";
request.ContentLength = bytedata.Length;



Stream postreqstream2 = request.GetRequestStream();
postreqstream2.Write(bytedata, 0, bytedata.Length);
postreqstream2.Close();
HttpWebResponse response = default(HttpWebResponse);

response = (HttpWebResponse)request.GetResponse();
StreamReader stream2 = new StreamReader(response.GetResponseStream());
StreamReader reader2 = new StreamReader(response.GetResponseStream());
kytro360
Light Poster
37 posts since Aug 2011
Reputation Points: 9
Solved Threads: 0
 

Bump....anyone?

kytro360
Light Poster
37 posts since Aug 2011
Reputation Points: 9
Solved Threads: 0
 

Bump, I need help still :/

kytro360
Light Poster
37 posts since Aug 2011
Reputation Points: 9
Solved Threads: 0
 

Bumnpppppppppppppp

kytro360
Light Poster
37 posts since Aug 2011
Reputation Points: 9
Solved Threads: 0
 

You ever get the solution to this? I'm having the same problem when i use a proxy..

lvnetwork
Newbie Poster
2 posts since Sep 2010
Reputation Points: 10
Solved Threads: 0
 

Never mind, figured out my problem.. Was passing a bad variable to httpwerequest proxy value..

lvnetwork
Newbie Poster
2 posts since Sep 2010
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: