【问题标题】:How to disable SSL check with Laravel http post如何使用 Laravel http post 禁用 SSL 检查
【发布时间】:2021-09-05 10:01:31
【问题描述】:

我正在尝试使用以下代码在 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;
    }
}

我收到以下错误:

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

我在 Apache 上本地运行我的 Laravel 应用程序,所以我承认没有运行 SSL 的事实,但我怎样才能绕过这个错误。在生产中会提供 ssl 吗??

【问题讨论】:

    标签: php laravel curl


    【解决方案1】:

    您应该在您的 Post 请求中使用 withoutVerifying()

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

    【讨论】:

    • 感谢这个工作,但是我得到一个异常说 withHeaders() 不是一个对应用程序至关重要的函数,我怎么能调用所有的静态类?
    • @NobleEugene 我更正了答案,请检查。
    • 我已经让 Laravel 承认它是一个函数,但是我收到来自端点的响应,说我没有设置任何授权标头
    • 好的,我现在开始工作了。非常感谢
    • 刚刚被选为答案。你绝对是摇滚人
    猜你喜欢
    • 2014-06-23
    • 2022-01-20
    • 1970-01-01
    • 1970-01-01
    • 2022-06-16
    • 1970-01-01
    • 1970-01-01
    • 2017-02-03
    • 2021-05-11
    相关资源
    最近更新 更多