0

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.

4

1 回答 1

0

没有大量信息可以继续,您是否有权访问代理服务器日志?

如果您检查返回变量,您会收到 405 错误吗?这表明代理不支持 POST 处理。

在调试方面,我要做的是将fiddler 设置为您的代理(或透明地使用它)然后您可以查看进出您的盒子的流量并分析数据以查看请求/响应中是否有任何异常.

于 2012-07-04T09:45:40.173 回答