PHP 卷曲字段

我正在尝试实现 TNT 标签 API,它想在请求中发送访问令牌。


我将访问令牌代码作为 POST 字段发送,但它不起作用。


有任何想法吗?


谢谢


我将访问令牌作为帖子字段发送,但它不起作用并返回错误 "{ "error": "invalid_request", "description": "所需的参数访问令牌丢失。" }"


function httpPostRequest($url, $strRequest,$auth)

        {

        $ch = curl_init();

        curl_setopt($ch, CURLOPT_URL, $url);

        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

        curl_setopt($ch, CURLOPT_POST, 1);

        curl_setopt($ch, CURLOPT_POSTFIELDS, $strRequest);

        curl_setopt($ch, CURLOPT_POSTFIELDS, $access_token);

        $isSecure = strpos($url, "https://");

        if ($isSecure === 0) {

            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);

        }


        $result = curl_exec($ch);

        $this->errorCode = curl_errno($ch);

        $this->errorMessage = curl_error($ch);

        return $result;

        }

预期:应返回成功消息实际: { "error": "invalid_request", "description": "The required parameter access token is missing." }


小怪兽爱吃肉
浏览 157回答 2
2回答

阿晨1998

H 选项意味着您应该在标题中传递参数。尝试这个:curl_setopt($ch, CURLOPT_HTTPHEADER, array(    'Authorization: Bearer YOUR_ACCESS_TOKEN'));

蛊毒传说

试试这个代码:function httpPostRequest($url, $strRequest,$auth)    {    $fields = array(        'strRequest' => $strRequest,        'access_token' => $access_token    );    $ch = curl_init();    curl_setopt($ch, CURLOPT_URL, $url);    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);    curl_setopt($ch, CURLOPT_POST, 1);    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));    $isSecure = strpos($url, "https://");    if ($isSecure === 0) {        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);    }    $result = curl_exec($ch);    $this->errorCode = curl_errno($ch);    $this->errorMessage = curl_error($ch);    return $result;    }
打开App,查看更多内容
随时随地看视频慕课网APP