the following is my code:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Timeout = timeout;
request.ReadWriteTimeout = timeout;
request.Proxy = new WebProxy("http://" + proxyUsed + "/", true);
request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.63 Safari/535.7";
request.CookieContainer = new CookieContainer();
request.AllowAutoRedirect = true;
ASCIIEncoding encoding = new ASCIIEncoding();
string postData = "";
foreach (string[] p in parameter)
{
if (postData != "")
postData += "&";
postData += string.Format("{0}={1}", p[0], p[1]);
}
byte[] data = encoding.GetBytes(postData);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = data.Length;
using (Stream newStream = request.GetRequestStream())
{
newStream.Write(data, 0, data.Length);
newStream.Close();
}
using (WebResponse myResponse = request.GetResponse())
{
using (StreamReader sr = new StreamReader(myResponse.GetResponseStream(), System.Text.Encoding.UTF8))
{
result = sr.ReadToEnd();
httpLink = myResponse.ResponseUri.AbsoluteUri;
sr.Close();
}
myResponse.Close();
}
I have encountered a problem that when makeing a POST http request to a Webpage. When I use direct connection it works fine. But if I use proxy, it throw a timeout exception. However, if I set the postData to be empty, it works fine even I am using proxy. What's the most likely reason for this? Thanks.