Angularjs HTTP 415

Asked

Viewed 70 times

0

I’m having trouble making a GET request, giving error 415 (Unsupported Media Type).

Although already set the headers he seems not to respect.

Does anyone have any suggestions of what to do to solve the problem? Remembering I’m new to Angularjs

$http.get('https://minhaurl.com.br/api/v1/tasks', 
            {
                headers: { 
                    'Accept': 'application/json; charset=utf-8',
                    'Content-Type' : 'application/json; charset=utf-8'
                }
            }
        );

inserir a descrição da imagem aqui

  • I see that it would be interesting to also put the code you have on the server that is called by this request.

  • @Giancarloabelgiulian the application of the back-end server is private, not even I have access there it, when I make a request via ajax (jQuery) goes smoothly. I managed to solve the problem temporarily in a totally wrong way, I went in the file Angularjs line: 11.949 where it declares the headers and added a xhr.setRequestHeader('Content-Type', 'Content-Type: application/json; charset=utf-8');

2 answers

0


Well, after much searching I found a 'better gambiarra' ... at the time of setting the options of the HTTP GET method you should pass Date blank '', automatically it will exchange the content-type for application/json utf8

More like this:

 $http({
   method: 'GET',
   data: '',
   url: 'https://minhaurl.com.br/api/v1/tasks'
});

0

Try it this way:

 $http({
       method: 'GET', 
       url: 'https://minhaurl.com.br/api/v1/tasks',
       headers: {
        'Content-Type' : 'application/json' 
       }
    });
  • Buddy, you’re still in the same trouble. I managed to solve the problem temporarily in a totally wrong way, I went in the file Angularjs line: 11.949 where it declares the header and added a xhr.setRequestHeader('Content-Type', 'Content-Type: application/json; charset=utf-8');

Browser other questions tagged

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