简体   繁体   English

ServiceStack将GET请求路由到POST方法

[英]ServiceStack routing GET requests to POST methods

I have been having an issue with Uri too long for a number of GET requests we currently have and our proposed solution is to issue post requests instead. 对于我们目前拥有的许多GET请求,Uri一直存在问题,而我们提出的解决方案是发出发布请求。

I'd prefer to keep my service methods using the GetXResponse Get(GetXRequest request) signature. 我希望保留使用GetXResponse Get(GetXRequest request)签名的服务方法。

Is there any way to configure ServiceStack to resolve to Get methods when the request starts with 'Get'? 当请求以“ Get”开头时,是否可以将ServiceStack配置为解析为Get方法?

Customize Request Handling with X-Http-Method-Override 使用X-Http-Method-Override自定义请求处理

There's no special heuristic of Request DTO naming to Get actions, but when making the request you can use the X-Http-Method-Override in either of the HTTP Header, QueryString or FormData to specify a different verb to execute the request as. 没有将请求DTO命名为Get操作的特殊方法,但是在发出请求时,您可以使用HTTP标头,QueryString或FormData中的X-Http-Method-Override指定不同的动词来执行请求。

Handle any Verb with Any() method 使用Any()方法处理任何动词

You can also use Any method to handle all verbs (ie inc GET/POST), eg: 您还可以使用Any方法来处理所有动词(即inc GET / POST),例如:

GetXResponse Any(GetXRequest request) { .. }

The Any method is used as a fallback, if you also have specific verbs with the same Request DTO it will use those instead, ie: Any方法用作后备方法,如果您还具有带有相同Request DTO的特定动词,它将改为使用这些动词,即:

GetXResponse Get(GetXRequest request) { .. }
GetXResponse Post(GetXRequest request) { .. }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM