我用的C#模拟表单post提交。下面是我用burp拦下的本机发出的请求包。可以看到,第一个参数名前面出现了莫名其妙的字符……搜索了好久也没找到原因。希望能得到各位前辈的指点。
网页要求的编码是utf-8,我这边用的编码也是utf-8。 burp包如图:
下面是我的代码。
//postdata
string data = string.Format("j_password={0}&j_username={1}&j_captcha_response={2}", psw, name, yzm);
//请求
string ans = Model.Variable.dd.HttpPost("http://ecar.95590.cn/ecar/j_spring_security_check", data, "http://ecar.95590.cn/ecar/view/ecar/login/login.jsp");
//dd.HttpPost
public string HttpPost(string Url, string postDataStr, string referer)
{
HttpWebRequest request = (HttpWebRequest) WebRequest.Create(Url);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.CookieContainer = this.cookie;
request.Referer = referer;
StreamWriter writer = new StreamWriter(request.GetRequestStream(), Encoding.GetEncoding("utf-8"));
writer.Write(postDataStr);
writer.Close();
HttpWebResponse response = null;
try
{
this.SetCertificatePolicy();
response = (HttpWebResponse) request.GetResponse();
}
catch (Exception)
{
}
if (response != null)
{
Stream responseStream = response.GetResponseStream();
StreamReader reader = new StreamReader(responseStream, Encoding.GetEncoding("utf-8"));
string str = reader.ReadToEnd();
reader.Close();
responseStream.Close();
return str.Replace(" ", "").Replace("rn", "").Replace("t", "");
}
return "error";
}