Tuesday 15 February 2011

asp.net web api - Mapping UrlEncoded POST Values in ASPNET Web API -



asp.net web api - Mapping UrlEncoded POST Values in ASPNET Web API -

i have post action within web api controller. header received is...

connection: close content-length: 19094 content-type: application/x-www-form-urlencoded expect: 100-continue host: xxxxxxxxxxxxx.co.uk

in iis logs can see general_request_entity as

"this posted data"

however not seem able grab piece of info using web api controller.

public httpresponsemessage post([frombody] string value)

the info beingness sent not seem fit format required. understanding microsoft decided posted frombody attribute needs prefixed "=" e.g.

="this posted data"

however info receiving (from source have no command over) not contain "=".

"this posted data"

my web api method hence ignores info sent in. have tried switch using formdatacollection info receiving not have key specified value seems end in key field seems bit odd.

public httpresponsemessage post(formdatacollection form) { string extracted = form.readasnamevaluecollection().getkey(0); }

i have tried making class/complex type wrap info posted doesn't contain key never seems match up.

am missing obvious. want piece of info posted web service string? help appreciated.

update

after much searching found few people same issue , appears have had move stack bit , utilize httprequestmessage. not ideal makes unit testing bit of nightmare.

public httpresponsemessage post(httprequestmessage message) { string extracted = message.content.readasstringasync().result; }

if has nicer way accomplish please allow me know.

handling post in webapi link

public class logindata { public string username { get; set; } public string password { get; set; } } [httppost] public httpresponsemessage authenticate(logindata login) { string username = login.username; string password = login.password; … }

asp.net-web-api

No comments:

Post a Comment