php 通过curl发送到标题x-auth [已关闭]

pkln4tw6  于 2023-01-29  发布在  PHP
关注(0)|答案(1)|浏览(102)

已关闭。此问题需要details or clarity。当前不接受答案。
**想要改进此问题?**添加详细信息并通过editing this post阐明问题。

昨天关门了。
Improve this question
我做的一切都对吗?我发送的服务器不允许我。怀疑是x-auth-key没有到达,或者是POST请求。
我这样发:

$fields = array( 'type' => 'buy');
      $postvars = '';
      foreach($fields as $key=>$value) {
        $postvars .= $key . "=" . $value. "&";
      }
        $header = array();
    $headers[] = "x-auth-key: ZTU1ODRjNzdasdasdasdKEYKEY";
    $headers[] = 'Content-Type: application/x-www-form-urlencoded; charset=utf-8';
    $state_ch = curl_init();
        curl_setopt($state_ch, CURLOPT_URL,"http://api.sitesite.com/account/orders");
        curl_setopt($state_ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($state_ch, CURLOPT_POSTFIELDS, $postvars);
        curl_setopt($state_ch, CURLOPT_HTTPHEADER, $headers);
        $state_result = curl_exec($state_ch);
    
        print_r($state_result);

也许你可以发送其他函数(只有标准的)?

nuypyhwy

nuypyhwy1#

您错过了CURLOPT_POST选项,请尝试此选项,它应该可以工作

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'http://api.sitesite.com/account/orders');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1); <-----
curl_setopt($ch, CURLOPT_POSTFIELDS, $postvars);

$headers = [];
$headers[] = 'X-Auth-Key: ZTU1ODRjNzdasdasdasdKEYKEY';
$headers[] = 'Content-Type: application/x-www-form-urlencoded; charset=utf-8';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close($ch);

相关问题