i want send via post request 2 parameters web api service. receiving 404 not found when try in following way, msdn:
public static void poststring (string address) { string data = "param1 = 5 param2 = " + json; string method = "post"; webclient client = new webclient (); string reply = client.uploadstring (address, method, data); console.writeline (reply); }
where json
json representation of object. did not worked, have tried query parameters in this post same 404 not found returned.
can provide me example of webclient sends 2 parameters post request?
note: trying avoid wrapping both parameters in same class send service (as found suggestion here)
i suggest sending parameters namevaluecollection.
your code when sending parameters namevaluecollection:
using(webclient client = new webclient()) { namevaluecollection requestparameters = new namevaluecollection(); requestparameters.add("param1", "5"); requestparameters.add("param2", json); byte[] response = client.uploadvalues("your url here", requestparameters); string responsebody = encoding.utf8.getstring(response); }
using uploadvalues make easier you, since framework construct body of request , won't have worry concatenating parameters or escaping characters.
Comments
Post a Comment