我正在使用以下代码发出 Get 请求:
TheRequest = (HttpWebRequest)WebRequest.Create(aURL);
TheRequest.Method = "GET";
TheRequest.CookieContainer = TheCookies;
TheRequest.UserAgent = GetUserAgent();
TheRequest.KeepAlive = false;
TheRequest.Timeout = 20000;
TheRequest.ReadWriteTimeout = 20000;
TheRequest.AllowAutoRedirect = true;
TheRequest.Headers.Add("Accept-Language", "en-us");
TheResponse = (HttpWebResponse)TheRequest.GetResponse();
TheResponseString = new StreamReader(TheResponse.GetResponseStream(), Encoding.ASCII).ReadToEnd();
在此之后,我按如下方式获取 cookie:
string theCookieHeader = TheResponse.Headers[HttpResponseHeader.SetCookie];
然后我将字符串处理为正确的 cookie 格式,并将其放入 cookie 容器中,以便在下一个 POST 请求中提供。从响应字符串 (TheResponseString) 我创建正确的 Post 数据和来自 cookiecontainer 的 cookie。
我的 POST 请求代码如下:
TheRequest = (HttpWebRequest)WebRequest.Create(aURL);
TheRequest.Method = "POST";
TheRequest.CookieContainer = TheCookies;
TheRequest.UserAgent = GetUserAgent();
TheRequest.KeepAlive = false;
TheRequest.Timeout = 20000;
TheRequest.ReadWriteTimeout = 20000;
TheRequest.AllowAutoRedirect = true;
TheRequest.ContentType = "application/x-www-form-urlencoded";
TheRequest.Headers.Add("Accept-Language", "en-us");
byte[] bytes = Encoding.ASCII.GetBytes(aPostDataString);
TheRequest.ContentLength = bytes.Length;
Stream oStreamOut = TheRequest.GetRequestStream();
oStreamOut.Write(bytes,0,bytes.Length);
oStreamOut.Close();
TheResponse = (HttpWebResponse)TheRequest.GetResponse();
TheResponseString = new StreamReader(TheResponse.GetResponseStream(), Encoding.ASCII).ReadToEnd();
现在的问题是我有两个网站,它们是合作伙伴网站,它们的一切都一样(看起来,但如果你有任何疑问,请告诉我),但是对于一个网站它工作正常,而对于另一个网站它给出了响应字符串网站错误页面。
请帮我看什么来诊断问题。