![](/img/trans.png)
[英]ASMX webservice not returning JSON, can only POST using application/x-www-form-urlencoded contentType
[英][FromBody]JToken param is null when ContentType: application/json or it's bad serialized when Contenttype: application/x-www-form-urlencoded [Fiddler]
正如主題所述,在嘗試通過Fiddler調用帶有請求正文的端點(POST)時遇到了問題。
有一個http api方法:
[HttpPost]
[Route("books")]
public IHttpActionResult GetBooks([FromBody]JToken filterRequest)
{...}
在Fiddler中,我使用請求標頭進行POST調用:
User-Agent: Fiddler Host: localhost Content-Length: 21 Content-Type: application/json
並且請求正文看起來像: { "title" : "Harry Potter"}
。 在調試它時,我得到空的filterRequest參數。
但是,當我使用Content-Type: application/x-www-form-urlencoded
,參數filterRequest參數不為null,但不幸的是包含錯誤的語法,例如:
{{“ {\\” title \\“:\\” Harry Potter \\“}”:“”}}
而且通過以下方式序列化是錯誤的:
var columnsFilter = new JavaScriptSerializer().Deserialize<Dictionary<string, string>>(filter);
我不知道我在做什么錯。 也許您遇到過類似的問題並且可以幫助您嗎?
事實證明,整個問題都基於錯誤的報價 。 我只能使用'
,並且發布的請求正文與Content-Type: application/json.
是正確的Content-Type: application/json.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.