【问题标题】:Trying to update data with guzzle尝试用 guzzle 更新数据
【发布时间】:2021-12-30 17:00:28
【问题描述】:

我正在使用 Guzzle,我需要更新数据,因此我正在尝试以下方法:

$request = $this->guzzleClient->put($this->url, [
    'headers' => $this->dcsheaders,
    'json' =>  json_encode([
        "status" => "Open",
        "accountNumber"=> "01236548",
        "reasonId"=>"ccaa8e8d-70ae-466d-b8c8-dd16bc5454e0"
    ])
]);

$a = $request->send();
var_dump($a);

但我收到了

导致400 Bad Request 响应

我尝试了其他类型,例如 form_params,但收到 403

【问题讨论】:

  • endpoit 使用什么样的身份验证?
  • 我正在发送以下标题 'content-type' => 'application/json', 'X-Api-Key' => PROXY_API_KEY
  • 删除 json_encode 如果你使用的是 json 请求参数,就像在 json 上做 json_encode

标签: php guzzle


【解决方案1】:

json 选项用于轻松上传 JSON 编码的数据作为请求的正文。

来源json request option guzzle

改成这个

$request = $this->guzzleClient->put($this->url, [
    'headers' => $this->dcsheaders,
    'json' =>  [
            "status" => "Open",
            "accountNumber"=> "01236548",
            "reasonId"=>"ccaa8e8d-70ae-466d-b8c8-dd16bc5454e0"
          ]
]);

【讨论】:

    猜你喜欢
    • 2017-08-26
    • 2019-12-13
    • 1970-01-01
    • 2016-12-29
    • 2018-05-05
    • 1970-01-01
    • 2017-05-17
    • 1970-01-01
    • 2019-10-01
    相关资源
    最近更新 更多