关于如何将POCO传递到webapi 2 GET而不是POST的任何建议?代码在下面,由于隐私问题无法粘贴真实代码。
GetDetail
是一种GET方法,但是由于需要将对象发送给它,因此已将其制成POST,我想提出一些如何处理这种情况的建议。
//client code
public class Field4Class()
{
public string field4a { get; set; }
public string field4b { get; set; }
}
public class POCO()
{
public string field1 { get; set; }
public string field2 { get; set; }
public string field3 { get; set; }
public Field4Class field4 { get; set; }
public string field5 { get; set; }
}
var poco = new POCO()
{
field1 = "value1",
field2 = "value2",
field3 = "value3",
field4 = new Field4Class()
{
field4a = "value4a",
field4b = "value4b"
},
field5 = "value5"
};
var response = client.PostAsJsonAsync("api/myController/Detail", poco).Result;
//Controller code
public class MyController : APIController
{
[HttpPost]
[Route("Detail")]
public SomeObject GetDetail(POCO poco)
{
// some processing
return new SomeObject someObject();
}
}