Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute:

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?

share|improve this question
2  
What is the error? – Stafford Williams Sep 2 at 12:52
    
@StaffordWilliams Added the error in my question – Pooja Sep 2 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 – rzysia Sep 2 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 – Yoni Levy Sep 2 at 13:10

1 Answer 1

up vote 0 down vote accepted

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 :)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.