首页 > 解决方案 > 无法做出 HTTP Post 请求响应:GuzzleHttp\Psr7\Response "Not Acceptable"

问题描述

我正在尝试post使用Illuminate\Support\Facades\Http.

我的请求 :

$response = Http::post(
            $this->api.'/auth',
            [
                'auth' => [
                    'username' => $this->username,
                    'password' => $this->password
                ]
            ]
        )->json('response');

While api, usernameandpassword被设置在一个__construct方法中。

这个请求在邮递员中运行良好。但是当我在 php 服务器上运行它时,我得到一个null. 我深入研究了回复,发现以下内容:

Illuminate\Http\Client\Response {#2741 ▼
  #response: GuzzleHttp\Psr7\Response {#2766 ▼
    -reasonPhrase: "Not Acceptable"
    -statusCode: 406
    -headers: array:5 [▼
      "Server" => array:1 [▶]
      "Date" => array:1 [▶]
      "Content-Type" => array:1 [▶]
      "Content-Length" => array:1 [▶]
      "Connection" => array:1 [▶]
    ]
    -headerNames: array:5 [▼
      "server" => "Server"
      "date" => "Date"
      "content-type" => "Content-Type"
      "content-length" => "Content-Length"
      "connection" => "Connection"
    ]
    -protocol: "1.1"
    -stream: GuzzleHttp\Psr7\Stream {#2765 ▼
      -stream: stream resource @28 ▶}
      -size: null
      -seekable: true
      -readable: true
      -writable: true
      -uri: "php://temp"
      -customMetadata: []
    }
  }

你知道如何解决这个问题吗?

标签: phplaravelapihttpilluminate

解决方案


您可以尝试将代码段导出为 PHP 代码,看看是否没有遗漏任何内容。如何获取代码片段


推荐阅读