I am consuming an API with basic Authentication oauth and returns: Incorrect request (400)

Asked

Viewed 519 times

0

Talk, you guys!

Next, I developed an api in spring boot and already tested with Postman and it works normally, its security is a very basic oauth authentication. Now I’m testing in an application in c# I have here to return the token to be able to consume the endpoints, however when I’m making the call to return the token is returning me:

"System.Net.WebException: 'O servidor remoto retornou um erro: (400) Solicitação Incorreta.'"

Follow the code below:

        WebRequest req = WebRequest.Create(@"http://localhost:8080/oauth/token");
        req.Method = "POST";

        req.Headers["Authorization"] = "Basic " + Convert.ToBase64String(Encoding.Default.GetBytes("apisustentacao:HHednf8iwFgre$$$@"));
        HttpWebResponse resp = req.GetResponse() as HttpWebResponse;

In Postman this working normally:

inserir a descrição da imagem aqui

Below is more picture of the Postman header:

inserir a descrição da imagem aqui

I appreciate anyone who can help me

  • Have you developed a Rest API? You could post the other Postman images showing the Headers, Body, Parameters?

  • Error 400 indicates that the request reached the server and was processed, but something sent was not correct. Did you try to capture the Webexception Response and verify what it says? Would that be the message you pasted Response?

  • Yes this is the message

  • added more print from Postman @Pedropaulo

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.