模拟POST 提交数据到别的网站。。那边接受到的汉字是乱码。。。怎么搞??
代码如下!
System.Net.WebClient WebClientObj = new System.Net.WebClient();
WebClientObj.Headers.Add("Content-Type ", "text/html; charset=iso-8859-1");
#region XXX
System.Collections.Specialized.NameValueCollection PostVars
= new System.Collections.Specialized.NameValueCollection();
PostVars.Add("Address", address);
PostVars.Add("Estate", louPan);
PostVars.Add("Bigarea", quyu);
PostVars.Add("Remark", reamrk);
PostVars.Add("Build_year", "2010");
PoPostVars.Add("chengzuType", chengzuType);
#endregion
if (type == "求购" || type == "出售")
{
PostVars.Add("Sale_unitprice", price.ToString());
//sbr.Append("&Sale_unitprice=" + Encod(price.ToString()));
}
else if (type == "求租" || type == "出租")
{
PostVars.Add("Rent_price", price.ToString());
//sbr.Append("&Rent_price=" + Encod(price.ToString()));
}
#
try
{
string url = "这里是对方提供的地址";
WebClientObj.UploadValues(url, "POST", PostVars);
}
catch (Exception ex)
{
Session["loginError"] = ex.Message;
}
UrlEncode一下吧
"UrlEncode"
url编码
%23%43 像这种格式的
这里有个例子,参考:
http://www.cnblogs.com/downmoon/archive/2009/11/09/1599199.html
WebClientObj.Headers.Add("Content-Type ", "text/html; charset=iso-8859-1");
这一行将提交的字符编码设置为 iso-8859-1,这样只能写英文,无法写中文,如下修改一下,使用 utf-8 编码。
WebClientObj.Headers.Add("Content-Type ", "text/html; charset=utf-8");