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

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -