|
//body是要传递的参数,格式"roleId=1&uid=2"
//post的cotentType填写:
//"application/x-www-form-urlencoded"
//soap填写:"text/xml; charset=utf-8"
public static string PostHttp(string url, string body, string contentType)
{
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
httpWebRequest.ContentType = contentType;
httpWebRequest.Method = "POST";
httpWebRequest.Timeout = 20000;
httpWebRequest.Headers.Add("x-requested-with", "XMLHttpRequest");
byte[] btBodys = Encoding.UTF8.GetBytes(body);
httpWebRequest.ContentLength = btBodys.Length;
httpWebRequest.GetRequestStream().Write(btBodys, 0, btBodys.Length);
HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
StreamReader streamReader = new StreamReader(httpWebResponse.GetResponseStream());
string responseContent = streamReader.ReadToEnd();
httpWebResponse.Close();
streamReader.Close();
httpWebRequest.Abort();
httpWebResponse.Close();
return responseContent;
}
private void button2_Click_1(object sender, EventArgs e)
{
PostHttp(
"https://passport.meituan.com/account/unitivelogin?service=banma_huoban&continue=http%3A%2F%2Fpeisong.meituan.com%2Faccount%2Fsettoken",
"captch=avxpa&email=18612403416&password=1qazxsw2&origin=account-login&fingerprint=&csrf=3fC2x6cX-ww48VAbYpQo89t9FjC5a2fHMXzc&commit=登陆",
"application/x-www-form-urlencoded");
}
结果就是请求异常
|
|