ServiceStack Client Put request and query parameters

I'm using the latest ServiceStack client lib in a .Net project and I'm having some issue making a PUT request. Especially it doesn't seem to take into account the type of parameter defined in the RequestDto object and put all params in the body (despite the param being defined as type ="query").

My Request object (auto-generated) looks like this:

[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; }

}

I make the call like this:

_apiClient.Put(new PutTestName(){UserId ="xyz..", Name="Bob"});

and I get "Resource not found" exception in return.

When I run the query manually using Postman (and putting both parameters in the Querystring) it works ok.

When debugging the C# client with fiddler I can see that no parameter is set to the query string and they are both passed in the body.

Edit: This what the Fiddler Request Raw looks like:

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"}

There is Azure API Management between the ServiceStack API and my call but I don't think this is the issue. The client code is setting the parameters in the body while they're supposed to be in the query.


If the same request works with POST then it's likely that WebDav is enabled and interfering with your PUT Request in which case you should disable WebDav so the request can reach ServiceStack unimpeded.

For debugging HTTP Interoperability issues like this, you should inspect (and provide here) the Raw HTTP Response Headers using a tool like Fiddler, Chrome Web Inspector or WireShark. If the HTTP Response Headers doesn't include an X-Powered-By: ServiceStack.. Header than it's likely the request has been intercepted and blocked before it reaches ServiceStack, eg IIS/ASP.NET or a forwarding proxy.

The client code is setting the parameters in the body while they're supposed to be in the query.

ServiceStack only sends parameters in the body for HTTP Verbs that don't have a request body like GET or DELETE , for Verbs with Request bodies, eg POST or PUT ServiceStack's JsonServiceClient will POST JSON as expected.

ServiceStack Services will accept parameters posted in either QueryString, JSON Request Body or x-www-form-urlencoded Content-Type. If you're not calling a ServiceStack Service you should be using a generic HTTP Client like HTTP Utils which will allow you to control exactly how the Request is sent, eg:

var response = absoluteUrl.ToPutUrl(new PutTestName {...});

Will send the results as x-www-form-urlencoded .

ServiceStack's .NET Service Clients are only for sending requests to ServiceStack Services.

链接地址: http://www.djcxy.com/p/68718.html

上一篇: ServiceStack请求POST正文作为查询字符串

下一篇: ServiceStack客户端放置请求和查询参数