c# - Sending dynamic form parameters to WebApi? -
i'm using webapi 1 ( visual studio: 2010 )
there rare scenarios client can send variable ( dynamic) number of parameters method. (via post
verb)
i've been trying test sending variable number of arguments :
post http://.../api/claims http/1.1 host: ... accept: */* content-type: application/x-www-form-urlencoded; charset=utf-8 content-length: 13 a=1&b=2&c=4
on server side :
[httppost] public dynamic newclaim1([frombody] dynamic al) { return request.createresponse(httpstatuscode.ok, (object)al); }
but empty object on response. ( 200 ok
)
attempt #2
i've tried ([frombody] object al)
attempt #3
i've tried (object[] al)
attempt #4
public class //using class holder { public object[] obj { get; set; } } [httppost] public dynamic newclaim1([frombody] al) { return request.createresponse(httpstatuscode.ok, al); }
but without success
question:
how can send dynamic post parameters method retrieve values.
nb :
- i don't want create class holders each combination...
- i don't want send json. i'm talking pure
post
x-www-form-urlencoded
- i know webapi doesn't support nativly multiple
[frombody]
parameters
you can retrieve form values using formdatacollection.
public void postform(formdatacollection formdata) { foreach (keyvaluepair<string, string> formentry in formdata) { string key = formentry.key; string value = formentry.value; } }
Comments
Post a Comment