Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to POST data on payload instead of formdata

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 ?

like image 577
Enrico Avatar asked Nov 27 '14 14:11

Enrico


People also ask

How do you send data in request payload?

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.

How can I post data as form data instead of a request payload?

$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) });

What is difference between request payload and form data?

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.

What is payload in post API?

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.


1 Answers

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" });        
like image 103
GarethL Avatar answered Sep 21 '22 09:09

GarethL