【问题标题】:Structure operation-input is missing a field "spec"结构操作输入缺少字段 \"spec\"
【发布时间】:2022-08-03 01:07:53
【问题描述】:

我正在尝试使用 Spring 的 WebClient 使用 vCenter REST API 生成支持包。当我使用 cURL 触发包创建(甚至伪造标头以模拟 Java 发送的内容)时,一切正常:

$ curl -A \"Apache-HttpAsyncClient/5.1 (Java/14.0.2)\" -X POST \'https://vcenter.internal.system:443/api/appliance/support-bundle?vmw-task=true\' -H \'vmware-api-session-id: 4d63eec20a2fd6baadfef6ba9c308f92\' -H \'Content-type: application/json\' -d \'{ \"components\": { \"VirtualAppliance\": [ \"ApplianceManagement\", \"Rhttpproxy\" ] }, \"description\": \"bundle\", \"partition\": \"\" }\' --insecure
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   204    0    74  100   130    217    382 --:--:-- --:--:-- --:--:--   601\"8459589f-0bcc-4a88-b579-8996c97c66aa:com.vmware.appliance.support_bundle\"

当我从 WebClient 执行相同操作时,我收到一个奇怪的 HTTP 400 错误:

{
    \"error_type\": \"INVALID_ARGUMENT\",
    \"messages\": [
        {
            \"args\": [
                \"operation-input\",
                \"spec\"
            ],
            \"default_message\": \"Structure operation-input is missing a field \\\"spec\\\"\",
            \"id\": \"vapi.data.structure.field.missing\"
        }
    ]
}

通过向 cURL 和 Apache 的 HTTP 客户端添加一些详细的日志记录,我看到发送的正文和标头是相同的,所以这是一个谜。

    标签: spring-webclient vcenter apache-httpclient-5.x


    【解决方案1】:

    我正在回答我自己的问题,因为我在网络上的任何地方都找不到与该问题远程相关的任何内容。解决方案是强制 HTTP 客户端使用 HTTP 1.1

    HttpAsyncClientBuilder clientBuilder = HttpAsyncClients.custom();
    clientBuilder.setVersionPolicy(HttpVersionPolicy.FORCE_HTTP_1);
    CloseableHttpAsyncClient client = clientBuilder.build();
    

    在查看请求和响应的原始数据后,我注意到 cURL 以纯文本形式发送标头,而 Apache HTTP 客户端显然会压缩它们。我怀疑 vCenter 方面存在一些错误行为,无论是在 HTTP 标头解压缩中,还是在一般的 HTTP/2 处理中。

    【讨论】:

      猜你喜欢
      • 2014-05-14
      • 2019-06-06
      • 1970-01-01
      • 1970-01-01
      • 2022-12-03
      • 2021-11-02
      • 1970-01-01
      • 2021-02-14
      • 1970-01-01
      相关资源
      最近更新 更多