HttpWebRequest erequestScore = (HttpWebRequest)WebRequest.Create("http://example.com");
postData = "post[title]=" + textbox_title.Text +"&post[content]=" + textbox_content.Text + "&fid=47&Subit=Submit";
data = encoding.GetBytes(postData);
erequestScore.Method = "Post";
erequestScore.ContentType = "application/x-www-form-urlencoded";
erequestScore.ContentLength = data.Length;
erequestScore.KeepAlive = true;
但问题是我的textbox_title.Text内容html代码有&符号和帖子数据将在&前停止。怎么解决? System.Web.HttpUtility.UrlEncode或System.Net.WebUtility?以及如何申请?
答案 0 :(得分:0)
你可以使用WebClient对象发布它,它可以发布一个NameValueCollection:
using (var wb = new WebClient())
{
var data = new NameValueCollection();
data["fid"] = "47";
data["someOtherName"] = "value";
var response = wb.UploadValues(url, "POST", data);
}