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.

6 Years
Discussion Span
Last Post by lvnetwork

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


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: Gecko/20070725 Firefox/";
request.ContentLength = bytedata.Length;

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

response = (HttpWebResponse)request.GetResponse();
StreamReader stream2 = new StreamReader(response.GetResponseStream());
StreamReader reader2 = new StreamReader(response.GetResponseStream());

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.