您好我正在尝试与API集成。我一直遇到一些问题,所以我一直与支持部门联系。
他们让我“捕获整个请求JSON”。说实话,我不知道该怎么做,我做了一些研究,我尝试过curl_getinfo($ session),它给了我信息,但不是我想要的。
这是我正在使用的卷曲代码。无论如何我可以将请求JSON打印到屏幕上吗?
$session = curl_init();
$putData = tmpfile();
$jsonString = $params;
fwrite($putData, $jsonString);
fseek($putData, 0);
curl_setopt($session, CURLOPT_HTTPHEADER, $headers);
curl_setopt($session, CURLOPT_BINARYTRANSFER, true);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
// Do you want CURL to output the headers? Set to FALSE to hide them
curl_setopt($session, CURLOPT_HEADER, true);
// pass the URL to CURL
curl_setopt($session, CURLOPT_URL, $url);
// Tell CURL we are using PUT
curl_setopt($session, CURLOPT_PUT, true);
// Now we want to tell CURL the were the file is and it's size
curl_setopt($session, CURLOPT_INFILE, $putData);
curl_setopt($session, CURLOPT_INFILESIZE, strlen($jsonString));
// right all done? Lets execute this
$output = curl_exec($session);
// Clean up by closing the file and closing curl
fclose($putData);
curl_close($session);
答案 0 :(得分:1)
根据以下内容更新您的代码...
$session = curl_init();
// your code ...
// you may need this option
// CURLOPT_HTTPHEADER => array("Content-type: application/json")
// getting results
$output = curl_exec($session);
$json = json_decode($output, true);
print_r($json);
// ...