Invoke-RestMethod 2 PHP_Curl

时间:2019-10-30 07:59:09

标签: powershell

在PS中,我做到了:

    $body=@{
        'code'='$code'
        'access_token'=$token
    }
    $result = Invoke-RestMethod -Uri $uri -Method Post -Body $body

完美。如何在PHP Curl中做同样的事情?

我已经尝试过这样的事情:

    $data = array("code" => $code, "access_token" => $token);
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $uri );
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
    curl_setopt($ch, CURLOPT_POST,           1 );
    curl_setopt($ch, CURLOPT_POSTFIELDS, array(
        "code=" . $code,
        "access_token=" . $token
        ));
    curl_setopt($ch, CURLOPT_HTTPHEADER, 
    array('ContentType:text/plain')); 

     $result=curl_exec ($ch);
     print_r($result);

但是我不断收到错误消息,例如:参数令牌丢失。

0 个答案:

没有答案