I'm trying to make a request to an Alfresco service from a web-script I made, passing some json data on the payload.
This is the Alfresco service:
http://localhost:8080/share/proxy/alfresco/api/internal/downloads
And I need to pass a json array whit some script node, like that:
var jsonData = "[{'nodeRef':'workspace://SpacesStore/920b43d4-e79c-40eb-96f3-1dff3a169929'}, {'nodeRef':'workspace://SpacesStore/f19fba4b-0cf6-4379-a858-70d0d7d9efb0'},{'nodeRef':'workspace://SpacesStore/6ea51288-9364-4070-a23b-499025a6c1f9'}]";
I make the call on this way
$.ajax({ url: serviceUrl, type: "POST", dataType: "json", data: jsonData });
Unfortunately when I chek the request list from the developer tools I see that my json data are passed as Form data on the request and I get an internal server error response.
I saw the same service used on another website and there the data are passed as payload, so, I think really need the data to be passed on the payload.
Does anyone know how to force it ?
To send the JSON with payload to the REST API endpoint, you need to enclose the JSON data in the body of the HTTP request and indicate the data type of the request body with the "Content-Type: application/json" request header.
$http({ method : 'POST', url : 'url', data : $. param(xsrf), // pass in data as strings headers : { 'Content-Type': 'application/x-www-form-urlencoded' } // set the headers so angular passing info as form data (not request payload) });
If an HTTP request has a message body, it is a "Request Payload" "Form Data" is a subset of Request Payload in which the body is encoded as key1=value1&key2=value2. Whenever Google Chrome can distinguish Form Data from a generic Request Payload, it customizes the formatting.
The Payload of an API Module is the body of your request and response message. It contains the data that you send to the server when you make an API request. You can send and receive Payload in different formats, for instance JSON.
I think it depends on the Content-Type header of the request; if the content type is "application/x-www-form-urlencoded" then it is shown under form data. If you put - for example - Content-Type: application/json the json should be part of the payload. You can use:
$.ajax({ url: serviceUrl, type: "POST", dataType: "json", data: jsonData, contentType: "application/json" });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With