如何使用 Laravel http post 禁用 SSL 检查

Nob*_*ene 17 php curl laravel

我正在尝试使用以下代码在 laravel 中向付款端点发出发布请求

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Http;
class AddCardController extends Controller
{
    //
    public function index()
    {
        return view("addcard");
    }
    public function requestPayment(Request $request)
    {
        $paystack_key = \config("app.paystack_key");
        $url = "https://api.paystack.co/transaction/initialize";
        $email = $request->user("distributors")->email;
        $fields = [
            "email"=>$email,
            "amount"=>50*100,
            "channels"=>["card"],
            "callback_url"=>"d"
        ];
        $query = http_build_query($fields);
        $response = Http::post($url,$fields)::withHeaders(["Authorization: Bearer $paystack_key",
        "Cache-Control: no-cache",])::withOptions(["verify"=>false]);
        return $response;
    }
}
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

cURL error 60: SSL certificate problem: unable to get local issuer certificate (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://api.paystack.co/transaction/initialize
Run Code Online (Sandbox Code Playgroud)

我在 Apache 本地运行我的 Laravel 应用程序,因此我承认没有运行 SSL,但如何绕过此错误。在生产中将提供 ssl 吗?

Moh*_*ini 50

withoutVerifying()您应该与您的 Post 请求一起使用。

  $response = Http::withoutVerifying()
        ->withHeaders(['Authorization' => 'Bearer ' . $paystack_key, 'Cache-Control' => 'no-cache'])
        ->withOptions(["verify"=>false])
        ->post($url,$fields);
Run Code Online (Sandbox Code Playgroud)

  • 为什么你有 `withoutVerifying()` 和 `withOptions(['verify' =&gt; false])` 因为它们是同一件事?您应该使用或! (5认同)