request.GetResponse (500) 内部服务器错误
private string GetWebForm(string url, string data, CookieContainer myCookieContainer) //提交表单,获取登陆返回信息
{
HttpWebRequest request;
HttpWebResponse response;
request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.CookieContainer = myCookieContainer; //设置cookie
//注意参数为中文时需要编码
//System.Web.HttpUtility.UrlEncode("搜 索", Encoding.GetEncoding("gb2312"));
byte[] byteRequest = Encoding.GetEncoding("gb2312").GetBytes(data);
request.ContentLength = byteRequest.Length;
Stream stream = request.GetRequestStream();
stream.Write(byteRequest, 0, byteRequest.Length);
stream.Close();
response = (HttpWebResponse)request.GetResponse();
//这句500错误
//try
//{
// response = (HttpWebResponse)request.GetResponse();
//}
//catch (WebException ex)
//{
// response = (HttpWebResponse)ex.Response;
//}
StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("UTF-8"));
string Msg = reader.ReadToEnd();
stream.Dispose();
reader.Dispose();
return Msg;
}
调用:
CookieContainer myCookieContainer = new CookieContainer();
string url = "http://180.166.7.150:8880/captcha.do?phoneNumber=13018917111&province