要使用HTTP POST请求,您可以尝试使用下面的代码发送一些数据:
检查“变种serverResponse”服务器响应。
string targetUrl = "http://www.url.url";
var postBytes = Encoding.Default.GetBytes(@"authenticity_token=pkhn7pwt3QATOpOAfBERZ%2BRIJ7oBEqGFpnF0Ir4RtJg%3D&question%5Bquestion_text%5D=TEST+TEST+TEST&authenticity_token=pkhn7pwt3QATOpOAfBERZ%2BRIJ7oBEqGFpnF0Ir4RtJg%3D");
var httpRequest = (HttpWebRequest)WebRequest.Create(targetUrl);
httpRequest.ContentLength = postBytes.Length;
httpRequest.Method = "POST";
using (var requestStream = httpRequest.GetRequestStream())
requestStream.Write(postBytes, 0, postBytes.Length);
var httpResponse = httpRequest.GetResponse();
using (var responseStream = httpResponse.GetResponseStream())
if (responseStream != null)
using (var responseStreamReader = new StreamReader(responseStream))
{
var serverResponse = responseStreamReader.ReadToEnd();
}
在线 使用(VAR requestStream = httpRequest.GetRequestStream()) 我得到这个错误:无法发送内容体与这个动词型。 – ISeeSounds
我的不好,我忘了设置httpRequest.Method POST,看到更新后的代码。 – animaonline
得到它的工作,谢谢我的男人 – ISeeSounds