Post with parameters using HttpWebRequest in C# -
having following code:
var request = httpwebrequest.create("https://api.channeladvisor.com/oauth2/token"); request.contenttype = "text/html"; request.method = "post"; request.headers.add("cache-control","no-cache"); request.headers.add("authorization", "basic " + base64translator.tobase64(system.text.encoding.ascii, devkey+":"+sharedsecret)); string postdata = " grant_type=refresh_token&refresh_token=a12sl1bhhjwerxm2nfth2efzw0yiw7462kahr43ucja"; var data = encoding.ascii.getbytes(postdata); request.contentlength = data.length; using (var stream = request.getrequeststream()) { stream.write(data, 0, data.length); } var response = (httpwebresponse)request.getresponse(); var responsestring = new streamreader(response.getresponsestream()).readtoend();
what's wrong? can't request can using external programs postman. see wrong in header?
error: "the remote server returned error: (400) bad request."
thanks!
your content type should application/x-www-form-urlencoded.
request.contenttype = "application/x-www-form-urlencoded";
wiki
Comments
Post a Comment