Skip to content

.Net API problem with production credentials

mayur pandit

mayur pandit

Asked Jan 10, 2018, 6:42 PM EST2 answers
Share
LinkedInX
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. 
Java
            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();
            }

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • mayur pandit
    0
    i have catch below exception :
     
    Web Exeption Status =protocal error
    invalid client
    0
  • mayur pandit
    0
    but when i send this reques using postman application with production credentials it's woking fine.
    0