ServiceStack路由使用数组作为参数
ServiceStack Route using array as parameters
我需要为使用 ServiceStack
的请求创建此 URL
,但我找不到生成此 URL
路由的方法:
http://server.com/myserver?service=2&item[0].reference=222&item[1].reference=233
下面是我的尝试:
[Route("myserver", "GET")]
public class Request1: IReturn<string>
{
public int Service { get; set; }
public List<Item> item { get; set;}
}
public class Item
{
public int Reference { get; set; }
}
首先,您应该避免设计 API 像这样通过 queryString 接受复杂类型,因为它会降低互操作性,因为每个支持发送复杂类型的框架都有不同的做法。
但不清楚为什么您要为 ServiceStack 请求创建这样的 url,因为 ServiceStack 期望 complex types using the JSV Format 已经内置到 C# 服务客户端中。
我假设您不是要将此请求发送到 ServiceStack 服务,而是想将其发送到第 3 方 API。 ServiceStack 的 C# Service Clients are opinionated towards communicating with ServiceStack Services, If you want to send requests to 3rd Party APIs I'd instead recommend using HTTP Utils 您可以自由地自己创建请求。
但一般来说,如果您想自定义 queryString 的生成方式,您可以 use a custom IUrlFilter。
我需要为使用 ServiceStack
的请求创建此 URL
,但我找不到生成此 URL
路由的方法:
http://server.com/myserver?service=2&item[0].reference=222&item[1].reference=233
下面是我的尝试:
[Route("myserver", "GET")]
public class Request1: IReturn<string>
{
public int Service { get; set; }
public List<Item> item { get; set;}
}
public class Item
{
public int Reference { get; set; }
}
首先,您应该避免设计 API 像这样通过 queryString 接受复杂类型,因为它会降低互操作性,因为每个支持发送复杂类型的框架都有不同的做法。
但不清楚为什么您要为 ServiceStack 请求创建这样的 url,因为 ServiceStack 期望 complex types using the JSV Format 已经内置到 C# 服务客户端中。
我假设您不是要将此请求发送到 ServiceStack 服务,而是想将其发送到第 3 方 API。 ServiceStack 的 C# Service Clients are opinionated towards communicating with ServiceStack Services, If you want to send requests to 3rd Party APIs I'd instead recommend using HTTP Utils 您可以自由地自己创建请求。
但一般来说,如果您想自定义 queryString 的生成方式,您可以 use a custom IUrlFilter。