【问题标题】:jersey and custom Expect header球衣和自定义 Expect 标头
【发布时间】:2014-05-06 10:30:58
【问题描述】:

代码优先:

Client client = Client.create();

WebResource webResource = client
        .resource("[link]");

ClientResponse response = webResource
        .header("Expect", "X-API-Key: [api_key]")
        .accept(MediaType.APPLICATION_JSON_TYPE)
        .post(ClientResponse.class, json);

String output = response.getEntity(String.class);

我的输出是:

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>417 Expectation Failed</title>
</head><body>
<h1>Expectation Failed</h1>
<p>The expectation given in the Expect request-header
   field could not be met by this server.
        The client sent<pre>
        Expect: X-API-Key: [api_key]
        </pre>
 </p><p>Only the 100-continue expectation is supported.</p>
 </body></html>

如果我使用 curl 和 php 一切正常。我已经在 Apache 中设置了:

<IfModule mod_headers.c>
    RequestHeader unset Expect early
</IfModule>

什么都没有。错误消失,但 X-API-Key 未设置。

【问题讨论】:

    标签: java php apache http-headers jersey


    【解决方案1】:

    有效!

    关闭重定向:

    client.setFollowRedirects(false);
    

    并删除Expect:

    ClientResponse response = webResource
            .header("X-API-Key", config.getKey())
            .type("application/json")
            .post(ClientResponse.class, json);
    

    干杯!

    【讨论】:

      猜你喜欢
      • 2019-10-20
      • 1970-01-01
      • 1970-01-01
      • 2012-03-12
      • 1970-01-01
      • 1970-01-01
      • 2014-06-07
      • 1970-01-01
      相关资源
      最近更新 更多