c# - POST NameValueCollection to Web API using WebClient.UploadValues for .NET 3.5 -
i have created web api serves pdf documents. have 4.5/4.0 client, javascript-only client, , i'm attempting create .net 3.5 client few older websites have. understand nuget few of libraries, understanding... httpclient works in 4.0 right now?
in case, i'd use webclient means getting done. have:
dim js new script.serialization.javascriptserializer dim client new net.webclient client.headers(net.httprequestheader.contenttype) = "application/x-www-form-urlencoded" dim serializeddata string = js.serialize(me.pdfreport) dim collection new namevaluecollection collection.add("value", serializeddata) dim response byte() = client.uploadvalues("http://www.mywebsite.com/api/report/post/", collection) i'm shoving serialized data namevaluecollection can return byte array pdf in it. can't seem show on web api side:
public function post(str namevaluecollection) byte() dim js new javascriptserializer dim obj pdfreport = js.deserialize(of pdfreport)(str("value")) dim rpt new reportservice(obj) 'return nothing (commented until figure out how values) end function what doing wrong? can't seem values on wire unless use uploadstring, can't grab response appropriate.
could share how raw request looks like?
also, try modifying action parameter formdatacollection , see if works. , have kind of check (change vb) catch model state errors.
if (!modelstate.isvalid) { throw new httpresponseexception(request.createerrorresponse(httpstatuscode.badrequest, this.modelstate)); }
Comments
Post a Comment