我在.Net項目中使用最新的ServiceStack客戶端庫,並且在發出PUT請求時遇到了一些問題。 特別是它似乎沒有考慮到RequestDto對象中定義的參數類型,並將所有參數放在body中(儘管param被定義爲type =「query」)。ServiceStack客戶端放置請求和查詢參數
我的Request對象(產生自動)看起來是這樣的:
[Route("/test/name", "PUT")]
public partial class PutTestName
: IReturn<PutTestNameResponse>
{
///<summary>
///the user id
///</summary>
[ApiMember(Description = "the user id", ParameterType = "query")]
public virtual string UserId { get; set; }
///<summary>
///the name
///</summary>
[ApiMember(Description = "the name", ParameterType = "query")]
public virtual string Name { get; set; }
}
我作出這樣的呼籲:
_apiClient.Put(new PutTestName(){UserId ="xyz..", Name="Bob"});
,我得到的回報 「找不到資源」 異常。
當我使用Postman手動運行查詢(並將兩個參數都放在Querystring中)時,它工作正常。
當使用fiddler調試C#客戶端時,我可以看到沒有參數設置爲查詢字符串,並且它們都在主體中傳遞。
編輯:這是什麼提琴手請求原始的樣子:
PUT https://xxxx/test/name HTTP/1.1
User-Agent: ServiceStack .NET Client 4.56
Accept-Encoding: gzip,deflate
Ocp-Apim-Subscription-Key: 783....
Content-Encoding: gzip
Accept: application/json
Content-Type: application/json
Host: xxx.net
Content-Length: 115
Expect: 100-continue
Connection: Keep-Alive
{"UserId":"xxx","Name":"Bob"}
還有就是ServiceStack API和我的通話之間Azure的API管理,但我不認爲這是問題。客戶端代碼正在設置參數,而它們應該在查詢中。
@Etienne您只添加了HTTP請求頭,HTTP響應頭是什麼樣的? – mythz
我不認爲這很重要,如果我使用PostMan進行相同的請求並將param放在查詢中,我會得到正確的結果。 如果我把它們放在身體中,我會得到404. 我是否錯過了什麼? – Etienne
@Etienne如果這不是ServiceStack服務,那麼您不應該使用ServiceStack的'JsonServiceClient'。您可以使用通用的HTTP客戶端,如[HTTP Utils](http://docs.servicestack.net/http-utils#posting-data)。 – mythz