HTTP GET method parameter format for object

こ雲淡風輕ζ 提交于 2019-12-11 00:54:22

问题


Can I set my request object by http parameters with GET method, if request contains not primitive object. I can do it for POST method with json, but does exist some GET alternative?

[DataContract]
[RestService("/foo")]    
public class FooRequest  
{
    [DataMember]
    public string Color1 { get; set; }


    [DataMember]
    public FooDto Dto { get; set; }

}

public class FooDto
{
    public string Color2 { get; set;}
}

In this example Color1 is set but how can I set Dto.color2?

http://server/fooservice/servicestack/foo?Color1=blue&Dto.Color2=red 

回答1:


In ServiceStack, you can set complex type properties on a QueryString by using the JSV Format. See this earlier answer for an example.

So to set the Complex Type Dto property your queryString would look like:

http://server/fooservice/servicestack/foo?Color1=blue&Dto={Color2:red} 


来源:https://stackoverflow.com/questions/13360098/http-get-method-parameter-format-for-object

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!