球衣和定制的Expect标题

时间:2014-05-06 10:30:58

标签: java php apache http-headers jersey

代码优先:

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未设置。

1 个答案:

答案 0 :(得分:0)

有效!

关闭重定向:

client.setFollowRedirects(false);

并删除Expect

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

干杯!