【问题标题】:php curl equivalent of post with contentphp curl相当于带有内容的帖子
【发布时间】:2016-05-25 03:21:26
【问题描述】:

我有以下 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 文件中回显的字符串

谢谢

【问题讨论】:

    标签: php post curl


    【解决方案1】:

    您可能有问题,因为您忘记添加上下文标题。

    试试这个代码:

    $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);
    

    【讨论】:

      猜你喜欢
      • 2014-09-17
      • 2023-03-29
      • 2012-03-15
      • 1970-01-01
      • 1970-01-01
      • 2015-06-10
      • 2012-10-12
      • 1970-01-01
      • 2017-08-29
      相关资源
      最近更新 更多