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.

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

Bump....anyone?

Bump, I need help still :/

Bumnpppppppppppppp

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.