我將以下代碼用作與POST請求對應的控制器操作。POST請求中的內容爲空
[HttpPost]
public HttpResponseMessage Post([FromBody]string value)
{
var response = new HttpResponseMessage(HttpStatusCode.Accepted)
{
Content = new StringContent(value, Encoding.UTF8, "text/xml")
};
return response;
}
我使用RESTClient插件爲Firefox生成請求。但是,每次該值都爲空時。請建議我做錯了什麼。
將從Fiddler捕獲的響應如下所示:
POST http://localhost/api/default/values HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: null
Accept-Encoding: gzip, deflate
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Content-Length: 5
Cookie: ai_user=5EE27B20-4A54-4651-820A-9D9654C2D891|2015-07-28T13:00:05.013Z
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
qwert
更新1: 作爲每意見,我試圖「值=」的格式,但它也沒有幫助。
POST http://localhost/api/default/values HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: null
Accept-Encoding: gzip, deflate
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Content-Length: 11
Cookie: ai_user=5EE27B20-4A54-4651-820A-9D9654C2D891|2015-07-28T13:00:05.013Z
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
value=qwert
上面的代碼片段是新請求的提琴手捕獲。還試過了JSON請求;但那也行不通。
POST http://localhost/api/default/values HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: null
Accept-Encoding: gzip, deflate
Content-Type: application/json; charset=UTF-8
Content-Length: 17
Cookie: ai_user=5EE27B20-4A54-4651-820A-9D9654C2D891|2015-07-28T13:00:05.013Z
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
{"value"="qwert"}
您是否使用過FIddler或類似工具來查看通過電線發送的內容? –
@DerekVanCuyk謝謝。我已將Fiddler請求捕獲添加到該帖子。 – dknight
自從我在UI界工作已經有一段時間了,但是不應該讓身體處於名稱 - 值對中?即值= qwert –