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 ?
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"
});