English 中文(简体)
Laravel Guzzle 客户错误:`POST https://'导致“415不支持的媒体类型”反应:(仅生产)
原标题:Laravel Guzzle Client error: `POST https://` resulted in a `415 Unsupported Media Type` response: (only in production)

我在寄出Guzzle:生产岗位申请时,有同样的数据,有同样的代码,在当地成功地应对了这一问题?

$response = $client->request( POST ,$ur,[
                form_params  => [
                  //data
               ]
            ]);

I have tried to using the exactly code in local to production and its expected to return success response instead of this error 415 Unsupported Media Type. I also try to extend header application/json and accept but same error.

问题回答

<代码>415 得不到支持的媒体 类型错误通常是指服务器由于有效载荷格式得不到支持而拒绝接受这一请求。 在你的情况下,似乎服务器正在期待配备一台JSON有效载荷,但你重新发送了form_params

In your Guzzle request, you can try changing form_params to json.

$response = $client->request( POST , $url, [
     json  => [
        //data
    ]
]);

此外,确保你重新制定<代码>Content-Type和Accept 标题改为application/json:

$response = $client->request( POST , $url, [
     headers  => [
         Content-Type  =>  application/json ,
         Accept  =>  application/json ,
    ],
     json  => [
        //data
    ]
]);




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签