Laravel 5.7在护照api上显示未经身份验证的回复,我在本地主机上设置了两个项目

时间:2018-12-03 10:44:01

标签: laravel rest curl laravel-5 laravel-passport

我在Laravel的本地都有2个站点,我试图从项目1到2调用基于护照的其余API。但是它显示了未经身份验证的响应,但在邮递员上运行良好。

我在控制器上使用的卷曲代码: $ curl = curl_init();

    curl_setopt_array($curl, array(
        CURLOPT_HEADER => 1,
        CURLINFO_HEADER_OUT => true,
        CURLOPT_SSL_VERIFYHOST => 0,
        CURLOPT_SSL_VERIFYPEER => 0,
        CURLOPT_URL => "http://localhost/payment/api/payrequest",
        CURLOPT_CUSTOMREQUEST => "POST",
        CURLOPT_POSTFIELDS => json_encode($data1),
        CURLOPT_HTTPHEADER => array(
            "Accept: application/json",
        "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6ImJiZDEzMzlmZjYyNGM2MWQxZjRiMDFlNmEwODA1ZDdmYTY0YzBhOGM4OGY2MjhlOWNiMzU1N2U3MWI1N2RkNDMyYjM5MDE5ZDI3NTU0ZmQyIn0.eyJhdWQiOiIxIiwianRpIjoiYmJkMTMzOWZmNjI0YzYxZDFmNGIwMWU2YTA4MDVkN2ZhNjRjMGE4Yzg4ZjYyOGU5Y2IzNTU3ZTcxYjU3ZGQ0MzJiMzkwMTlkMjc1NTRmZDIiLCJpYXQiOjE1NDM4MjE3NDIsIm5iZiI6MTU0MzgyMTc0MiwiZXhwIjoxNTc1MzU3NzQyLCJzdWIiOiIyIiwic2NvcGVzIjpbXX0.FHkGFHJGMXH6QAInbAxSkqz7rmSZwfr0yd9mFFBtVpCUe5m1Xrw7h3EMlZ8JqHqmYwcosofjwSMuSn5ihQax726qgz7QExYaisZ0KQKNlHOtTTyk2gsybs0_ZI63UTk_-0NO_uiGTdZkWQn_fvYSpCIq-kRZohJ2RoXzd5iCv0oYBUKuGlnXlunuBgteDY0TyOAM4qvN18O2JBHjiVxGMNmkah3Gq_REUxAY93SYucGu_4fAgtjCVNfdhtmjNSE4eflPr7RZ5ip-nQFfZBjDEQZUY8DqQNW7k6LZZiJfWd8685IByMOKric5EUBpUJ1zAyMbsKrbeCuvnfKPWhiULgdPYe7riML78ek4e-Ec1RYpmKva9zw6aP1s85W1WwZzWVQp4B-9aM0D81g172pjl9Op5EsvqgLwo3ZFWFUTGZ14rp9KQ5ZbLJRiwiVCstlxpFECY8H5UjVXOXnQSGMgx_5TAlcc_CfQXkJGhhO_MtQwCA7tNCfz44DC4Wjf9Eji8Hc0hnTULMShMAMwLHl8bUCtfcr2iGGdw4jHmaEbmEkaNpK4MjIUiTFjjSiGZXvWxg5UjqRlvXl3AWAysh3ez0ea_aC_OiKWP-pkJbClPNK5inAY9JuioyTijaNM4urLlh0y0JOQmF4lNq8NhzRNuF81jIZ3xsyyrYxubMEi2oI",
        'Content-Type: application/json',
        'cache-control: no-cache',
        'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW',
        'postman-token: a3e3f245-b27d-bb1e-997e-8dae837ccb8d'
          ),

    ));

    $response = curl_exec($curl);
    echo "<pre>";
    print_r(curl_getinfo($curl));
    echo "</pre>";
    $err = curl_error($curl);
    curl_close($curl);

    if ($err) {
        dd($err);
    } else {
        dd($response);
    }

无法确定确切的问题,因此还添加了.htaccess授权代码。

RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

另外,如果我尝试不使用身份验证,也可以正常工作,但可以使用Route :: group(['middleware'=>'auth:api'],function() {

} 它不醒。

0 个答案:

没有答案