我在.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