我试图通过PHP实现以下PHP代码POST JSON:卷曲(SOME FORCE.COM网站是指这意味着我要发布的URL标签):无法通过PHP检索JSON POST:卷曲
$url = "<SOME FORCE.COM WEBSITE>";
$data =
'application' =>
array
(
'isTest' => FALSE,
key => value,
key => value,
key => value,
...
)
$ch = curl_init($url);
$data_string = json_encode($data);
curl_setopt($ch, CURLOPT_POST, true);
//Send blindly the json-encoded string.
//The server, IMO, expects the body of the HTTP request to be in JSON
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER,
array
(
'Content-Type:application/json',
'Content-Length: ' . strlen($data_string)
)
);
$result = curl_exec($ch);
curl_close($ch);
print_r($result);
echo '<pre>';
echo $_POST;
$jsonStr = file_get_contents('php://input'); //read the HTTP body.
var_dump($jsonStr);
var_dump(json_decode($jsonStr));
echo '</pre>';
的上述输出是以下:
"Your TEST POST is correct, please set the isTest (Boolean) attribute on the application to FALSE to actually apply."
Arraystring(0) ""
NULL
行,我通过使用json_encode正确格式化的JSON数据的上述确认,并且SOME FORCE.COM网站确认“isTest”的值是假。但是,我没有从“var_dump($ jsonStr)”或“var_dump(json_decode($ jsonStr))”获取任何内容。我决定忽略这一事实,并设置“isTest”为FALSE,假设我没有得到任何JSON数据,因为我设置“isTest”为真,但出现混乱时,我设置“isTest”为假:
[{"message":"System.EmailException: SendEmail failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Missing body, need at least one of html or plainText: []\n\nClass.careers_RestWebService.sendReceiptEmail: line 165, column 1\nClass.careers_RestWebService.postApplication: line 205, column 1","errorCode":"APEX_ERROR"}]
Arraystring(0) ""
NULL
我仍然没有收到任何JSON数据,最终邮件无法发送。我相信这个问题是由于空的电子邮件正文产生的,因为没有任何内容来自“var_dump($ jsonStr)”或“var_dump(json_decode($ jsonStr))”。你能帮我检索JSON POST吗?我真的很感激任何提示,建议等。谢谢。
检查您的回复标题,如内容类型! – Bigood 2013-02-27 08:53:58
$ jsonStr在哪里?你在哪里指定它? – Ghigo 2013-02-27 08:55:07