在 Laravel 中发送带有 json 对象数据的 post 请求

我想在 Laravel 中使用 Http 门面发送请求,但我无法传递 json 对象数据,它必须只是数组。

Http::withHeaders(['Content-Type' => 'application/json'])->withOptions([
        'headers' => $coockie
    ])->post($this->policy_url . $address,json_encode($data));

我的数据变量值:

        $data = [
        "document" => [
            "customerId" => 1,"currencyId" => 1,"settlementPolicyId" => 8,"storeId" => 16,"documentPatternId" => 2,"items" => [
                [
                    "productId" => 193,"unitId" => 2,"quantity" => 1,"TrackingFactor1" => "1214","PartTrackingFactorRef1" => 1053,"TrackingFactorHasQuantity1" => true,"TrackingFactorValue" => "‏test","fee" => 0
                ]
            ]
        ],"payments" => [
            [
                "key" => "Cash","amount" => 445810,"attr" => []
            ]
        ]
    ];

错误:

TypeError Argument 2 passed to Illuminate\Http\Client\PendingRequest::post() must be of the type array,string given
QQ170102852 回答:在 Laravel 中发送带有 json 对象数据的 post 请求

在将其发送到请求之前先生成 <dependency> <groupId>io.netty</groupId> <artifactId>netty-all</artifactId> <version>4.0.42.Final</version> </dependency>

json_encode($data)
本文链接:https://www.f2er.com/1945.html

大家都在问