Pergunta

Code first:

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);

my output is:

<!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>

if I use curl and php everything works fine. I have set in Apache:

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

and nothing. Error disappeared but X-API-Key is'nt set.

Foi útil?

Solução

It works!

Turn off redirects:

client.setFollowRedirects(false);

and remove Expect:

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

Cheers!

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top