[英]How to see PUT Request
嗨,我正在尝试与API集成。 我对此一直遇到一些问题,所以我一直与支持部门联系。
他们要求我“捕获整个请求JSON”。 老实说,我不确定如何做到这一点,我已经做了一些研究,并且尝试了curl_getinfo($ session),它可以提供信息,但不能提供所需信息。
这是我正在使用的curl代码。 无论如何,我可以将请求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);
根据以下内容更新代码...
$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);
// ...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.