【问题标题】:JSON param through Guzzle 6 post always errors out通过 Guzzle 6 发布的 JSON 参数总是出错
【发布时间】:2016-07-23 00:01:17
【问题描述】:

说 2 条消息之一时总是出错。 {"message":"Required field 'specList' is not specified"} 或者如果我添加 specList 那么它会说 '400 Bad Request' response: {"message":"Can not deserialize instance of java.util.ArrayList out of VALUE_STRING token"}

这就是我所拥有的:

    $client = new GuzzleHttp\Client(['base_uri' => 'https://someURL/PrismGateway/services/rest/v1/']);
    $res = $client->request('POST', 'vms/'.$vmId.'/clone',
        [
            'verify' => false,
            'auth' => ['user', 'pass'],
            'json' => [
                'specList' => '[{"name":"test9"}]'
                //tried 'create.dto.acropolis.VMCloneDTO' => '{"specList":[{"name":"test9"}]}'
            ]
        ]
    );

如果我使用create.dto.acropolis.VMCloneDTO,它会告诉{"message":"Required field 'specList' is not specified"},如果我将其更改为specList,它会给我上面的反序列化错误。我不确定我做错了什么,但 api 中的实际参数被列为 create.dto.acropolis.VMCreateDTO 并且它期望 specList 响应作为 json 数据类型。

有人帮我弄清楚为什么它不起作用?

【问题讨论】:

    标签: php guzzle guzzle6


    【解决方案1】:

    想通了。去掉了json,加了body

    'body' => '{"specList":[{"name":"test9"}]}'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-03
      • 1970-01-01
      • 2020-03-19
      • 1970-01-01
      • 1970-01-01
      • 2019-05-31
      • 1970-01-01
      • 2019-10-19
      相关资源
      最近更新 更多