我有以下get_file_contents代码
$opts = array('http' => array(
'method' => 'POST',
'header' => 'Content-type: application/vnd+cbnv+endpoint',
'content' => $encryptedString
));
$buff = @file_get_contents($URL, false, stream_context_create($opts));
如何使用curl完成此操作?
我正在尝试这样的事情
$handle = curl_init();
curl_setopt($handle, CURLOPT_URL, $URL);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_POST, true);
curl_setopt($handle, CURLOPT_POSTFIELDS, $encryptedString);
$ret = curl_exec($handle);
curl_close($handle);
$ ret为NULL,它应该是@ $ URL文件中的一个字符串
谢谢
答案 0 :(得分:0)
你可能会因为添加上下文标题而遇到问题。
试试这段代码:
$handle = curl_init();
curl_setopt($handle, CURLOPT_URL, $URL);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_POST, true);
curl_setopt($handle, CURLOPT_POSTFIELDS, $encryptedString);
curl_setopt($handle, CURLOPT_HTTPHEADER, ['Content-type: application/vnd+cbnv+endpoint']);
$ret = curl_exec($handle);
curl_close($handle);