C# Httpwebreqest post参数

C# Httpwebreqest post参数,c#,post,httpwebrequest,C#,Post,Httpwebrequest,但问题是,我的textbox_title.Text包含有&symbol和post数据的html代码将在&之前停止。如何解决?System.Web.HttpUtility.UrlEncode或System.Net.WebUtility?以及如何应用?您可以使用WebClient对象发布它,该对象可以发布NameValueCollection: HttpWebRequest erequestScore = (HttpWebRequest)WebRequest.Create("http://examp

但问题是,我的textbox_title.Text包含有&symbol和post数据的html代码将在&之前停止。如何解决?System.Web.HttpUtility.UrlEncode或System.Net.WebUtility?以及如何应用?

您可以使用WebClient对象发布它,该对象可以发布NameValueCollection:

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;

我自己解决了,用System.Web.HttpUtility.UrlEncode包围的参数是好的
using (var wb = new WebClient())
{
   var data = new NameValueCollection();
   data["fid"] = "47";
   data["someOtherName"] = "value";
   var response = wb.UploadValues(url, "POST", data);
}