mayur pandit

mayur pandit

  • 1.4k
  • 333
  • 61.3k

.Net API problem with production credentials

Jan 10 2018 11:42 PM
I have wokring with third party api with post method.
when i use staging credential's of thired party api it's working.
but when i use production credentials it's not woking , it's return
"The remote server returned an error: (400) Bad Request error"
error but production credential's woking in postman application fine.
where is actually gong wrong i don't understand.i have provide here
my code please check and help,
Thank's in advance. 
string url = "";
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
request.Method = "POST";
string client_id="";
string client_secret = "";
string scope = "";
string grant_type = "";
var postData = "client_id:"+client_id.Trim()+"\r\n";
postData += "client_secret:" + client_secret.Trim() + "\r\n";
postData += "scope:" + scope.Trim() + "\r\n";
postData += "grant_type:"+ grant_type.Trim() +"";
string data = postData; // make sure this is URL encoded
request.ContentType = "application/x-www-form-urlencoded";
using (Stream requestStream = request.GetRequestStream())
using (StreamWriter writer = new StreamWriter(requestStream, Encoding.ASCII))
{
writer.Write(data);
}
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
// careful, non-2xx responses will throw an exception
using (Stream responseStream = response.GetResponseStream())
using (StreamReader reader = new StreamReader(responseStream))
{
string a = reader.ReadToEnd();
}

Answers (2)