2013-02-27 122 views
0

我试图通过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吗?我真的很感激任何提示,建议等。谢谢。

+0

检查您的回复标题,如内容类型! – Bigood 2013-02-27 08:53:58

+0

$ jsonStr在哪里?你在哪里指定它? – Ghigo 2013-02-27 08:55:07

回答

0

我自己解决了这个问题。我不确定我是否正确地做了这件事,但事实证明我的代码是完美的。我一直在刷新我的网站,从我发布到某些FORCE.COM网站。我相信管理某些FORCE.COM网站的人在他们的最后遇到了问题。我所做的一切都没有错。出于某种原因,我得到了一段代码202和一些乱码文本。我很乐意展示输出结果,但我不想再次发布POST,以便管理我开发的某个FORCE.COM网站的人员。谢谢你们的帮助。