我有一个非常简单的场景,我无法工作。我正尝试使用cURL将JSON字符串发布到RESTful结点,以便通过服务器上的HTTPS和RESTeasy发送请求。RESTeasy使用JSON体POST - HTTP 100
我卷曲POST正是如此配置:
$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;
而且RestEasy的recipiant样子:
@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;
}
我有这个问题是该请求挂起约30秒,然后返回一个HTTP 100响应。据我所知,HTTP 100意味着继续处理其余的请求,但我不明白我应该怎么做。
我试图删除Content-Length头,但显然我得到了411(需要内容长度),所以这也不是一个选项。
这可能是内容类型的问题吗?任何帮助深表感谢。
可能的重复http://stackoverflow.com/questions/4271621/php-curl-post-json – cmbuckley 2012-03-28 22:49:45
根据php.net,如果你传递一个数组到'CURLOPT_POSTFIELDS'它被编码为'multipart/form-data '。如果直接传递json字符串会发生什么? – abraham 2012-03-28 22:50:21
@cbuckley我看到了,但没有提到RESTeasy在另一方面,这是50%的潜在问题在这里... – travega 2012-03-28 23:02:56