Dear all,
What would be the most appropriate component to send a POST request to a REST server and get JSON formated results?
Using curl (outside PP) I can write the folowing command, which returns JSON.
curl -X POST -H 'Accept:application/json' -H 'Content-Type:application/json' -d 'my query to the server' -v http://server:port/rest/destination
The idea would be to send the command from PP, get a single record back containing JSON formated results and parse it using the Data from JSON component.
Thanks,
Pierre

Hi Pierre,
The HTTP Connector is the best component for this task.
Kind regards,
Jason Benedict
Hi Jason, thanks for the quick answer.
I'm able to send a GET request with this protocol but I'm not sure how to setup a POST request. Header setup is ok, in which parameter would you put the query (-d parameter in curl), whci has to be JSON formated for the remote server?
Kind regards,
Pierre
I've had sucess using the Request Body parameter of HTTP Connector for POST requests. Enter your JSON string surrounded by single quotes.
'{"person":{"name":"bob","age":25}}'
For multi-line JSON each line needs to be enclosed in single quotes and concatenated using Pilotscript (.) dot operator.
'{' .
'"person" : {' .
'"name" : "bob",' .
'"age" : 25' .
'}' .
'}';
I did put the exact same query (single line b/ single quptes) as in the curl call above in the "request body" parameter of the HTTP Connector component, it still returns "bad request". Is this the right parameter?
HTTP request to server failed. 400 - Bad Request
CHttp::CheckResponseHeader: Pipeline Pilot exception rethrown
CHttp::internalOpen: Pipeline Pilot exception rethrown
CHttp::OpenEx: Pipeline Pilot exception rethrown
CHttpPost::onProcess: Pipeline Pilot exception rethrown
-> HTTP Connector (HTTP Connector) - error during Data Record Processing phase
CProtocolStd::onProcess: Pipeline Pilot exception rethrown
CProtocol::onProcess: Pipeline Pilot exception rethrown
CComponentRunner::CallOnProcess: exception caught, calling onFinalize before rethrow
To further investigate the http 400 error try entering 400 in the 'Additional Allowed Response Codes' parameter of HTTP Connector.
This should avoid the PP error dialog and send full server response out the pass port. FWIW I'm using PP8.5
Hi Mike, actually I was using PP8.5, we have not yet migrated our servers, that should be done soon. I just tried with PP9.1, the component parameters are better organised with the "Send request body" and "Content type" parameters.
It's now working well with 9.1. I'll figure out what was wrong with 8.5, I tried many different things, so I must have missed the correct combination!
Hopefully, parsing json results might be easier. Get rather than Post return error 405, so the issue was elsewhere.
Thanks
Maybe you are not specifying the POST method in the parameters? Incidentally, which version of PP are you using, since the HTTP Connector had something of a face lift in the 9.x releases.
In 9.x:
e.g. '[{"key1":"value1"},{"key2":"value2"}]'
Hope that helps...
Mike