[英]Put call works in PostMan but not in RestSharp: Getting a bad request
我想用Put命令調用端點。
在郵遞員
我可以舉例https://example.com/customers/106
。 然后我添加一個類型application/json
的主體(在raw
下)。
當我Put
這個身體放到端點時,我得到200 OK
。
我使用的端點需要兩個自定義標頭和一個內容類型,我在標頭下做了。 所以我添加了三個標題: X-AppSecretToken
, X-AgreementGrantToken
和Content-Type
( to application/json
)。
在RestSharp中
我在這里使用以下內容。 該putstr
是完全一樣的身體我Put
我在郵差做:
var restclient = new RestSharp.RestClient("https://example.com");
var request = new RestRequest("/customers/" + customerId, Method.PUT);
request.AddHeader("X-AppSecretToken", systemToken);
request.AddHeader("X-AgreementGrantToken", userToken);
request.AddHeader("Accept", "application/json");
request.AddJsonBody(putstr);
var response = restclient.Execute(request);
現在,當我這樣做時,我得到以下響應,這是我調用的API的自定義錯誤:
"{\"message\":\"Error converting value SOME STUFF}}\\\" to type 'eco.rest.Models.Customer'. Path '', line 1, position 605.\",\"errorCode\":\"E00500\",\"developerHint\":\"The JSON payload could not be parsed. The error message should give you a good indication of where the error is located. One common reason for this error is a missing '{' or a '}' in your payload.\",\"logId\":\"123fc6fb4964a141f612ae8ae7571446\",\"httpStatusCode\":400,\"logTime\":\"2018-05-20T21:56:56\"}"
怎么修?
通常情況下,我永遠不會問這個問題。 如果有人問,我會說:打開Fiddler或類似的工具,看看請求是如何不同的。
我有一些麻煩,因為它是HTTPS。
當我通過我的代碼調試時,我根本看不到Fiddler里面的調用。 我也安裝了查爾斯,但也沒有運氣。 不確定是什么問題。
但是,我認為讀這篇文章的人可能會想出這個問題。 我自己的假設是我可能以錯誤的方式添加了標題,JSON正文編碼不同或類似 - 但我真的不確定如何繼續前進。 我希望有人能幫幫忙!
您的putstr
值似乎是JSON值。
AddJsonBody
會將此JSON值轉換為另一個JSON值。
您應該使用原始對象而不是putstr
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.