I have a very simple scenario which I cannot get to work. I am trying to POST a JSON string to a RESTful endoint using cURL to sent the request over HTTPS and RESTeasy on the server.
My cURL POST is configured thusly:
$ch = curl_init();
$content = json_encode($validJsonString);
curl_setopt($ch, CURLOPT_URL, 'https://foobar.com/test?trackingId=12345');
curl_setopt($ch, CURLOPT_POSTFIELDS, array('json' => $content));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
$headers = array(
'Content-Type: application/json',
'Content-Length: ' . strlen($content)
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec ($ch);
$httpResponseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$json = json_decode($response);
curl_close ($ch);
return $json;
And the RESTeasy recipiant looks like:
@POST
@Path("/test")
@Produces("application/json")
public String addObjectCommentAsJSON( @FormParam("json") String validJsonString,
@QueryParam("trackingId") String trackingId) {
Gson gson = new Gson();
SomeObject someObject = gson.fromJson(validJsonString, SomeObject.class);
String responseString = methodThatReturnsAJsonString(trackingId, someObject);
return responseString;
}
This issue I am having is that the request hangs for about 30 seconds and then returns a HTTP 100 response. I understand that HTTP 100 means continue with the remainder of the request but I don’t understand how I am supposed to do that.
I tried to remove the Content-Length header but obviously I get a 411 (needs content length) so that’s not an option either.
Is it an issue with the content type perhaps? Any help is much appreciated.
Ok so thanks to @cbuckley and @abraham’s suggestions in their comments I have been able to work through the issues. This is what I needed to do:
1-> Change the contents of the POST body so instead of
curl_setopt($ch, CURLOPT_POSTFIELDS, array('json' => $content));I now havecurl_setopt($ch, CURLOPT_POSTFIELDS,json_encode($validJsonString));2-> I created a custom
@Providerwhich parsed a JSON string to a Java POJO with the same structure:3-> Finally the structure of the recipient method has to change slightly:
And that all flowed through nicely.