AngularJS - Getting 415 Unsupported Media Type error for $http.put method with encoded parameter

17 Views Asked by At

I have one endpoint(PUT method) '/api/updateCode' which is expecting a code as parameter that is in encoded format.('/api/updateCode/{code}' - sample swagger documentation)

In the controller Im calling the endpoint like below

controller.js code

$scope.update= function (code) {
var encodedCode = window.btoa(code);
$http.put('/api/upDateCode/' + encodedCode)
  .success(function (data) {
    console.log(data);
  })
  .error(function (data) {
    console.log(data);
  });
}

When I ran this code in the network tab I can see 415 Unsupported Media Type error. I tried some other ways to pass header values etc.. but not at all working.

From postman and swagger the api is returning correct response.

Is there any working solution for this?

0

There are 0 best solutions below