3

I have to 'PUT' some json data to a server. The below code is throwing an error

$rootScope.request.data = {"name": "John", "surname":"Doe"}
var uri = //some REST API
var action = $http({
    method: 'PUT',
    url: uri,
    data: $rootScope.request.data
});

The error thrown is:

Flow not found for resource: Resource{displayName='null', uri='/signup'} (org.mule.module.apikit.exception.ApikitRuntimeException). Message payload is of type: NullPayload

But when I do this, it works

$rootScope.request.data = {"name": "John", "surname":"Doe"}
var uri = //some REST API
var action = $http.put(uri, $rootScope.request.data);

The 'action' is then pushed in an array and the requested are fired using a $q.all. The success and error is handled in the $q

Was wondering what is the difference between them? Have I missed something in my first request?

3
  • @StaffordWilliams Added the error in my question Commented Sep 2, 2015 at 12:57
  • you can simple press F12 and see what requests are send from your code (ex. in 'network' in chrome), so you can see the difference between them Commented Sep 2, 2015 at 13:02
  • $http.put is just a wrapper. Take a look at the source, line 1153 and 1183-1193 github.com/angular/angular.js/blob/master/src/ng/http.js Commented Sep 2, 2015 at 13:10

1 Answer 1

5

Solved the issue. Thanks to @rzysia for the pointer.

When I compared the requests, the Content-Type in the 1st case was sent as 'text/plain' and in the second case it was 'application/json'. The REST API needed 'application/json' as the content type.

Adding the below code did the trick

$rootScope.request.data = {"name": "John", "surname":"Doe"}
var uri = //some REST API
var action = $http({
    method: 'PUT',
    url: uri,
    headers: {"Content-Type": "application/json;charset=UTF-8"},
    data: $rootScope.request.data
});

These links were helpful: https://github.com/angular/angular.js/issues/2149 and Content-Type header not being set with Angular $http

And big thanks to all who put in their 2 bit :)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.