要使用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