webapiのサンプルを作成しているのですが、
以下のコードを実行した場合、
java
1package com.example; 2 3import javax.ws.rs.client.ClientBuilder; 4import javax.ws.rs.client.Entity; 5import javax.ws.rs.core.MediaType; 6import javax.ws.rs.core.MultivaluedHashMap; 7 8import org.glassfish.jersey.apache.connector.ApacheConnectorProvider; 9import org.glassfish.jersey.client.ClientConfig; 10import org.glassfish.jersey.client.ClientProperties; 11/* 12 * 以下urlを参考にしました。 13 * hogehoge 14 * hogehoge 15 * */ 16public class Main3 { 17 public static void main(String[] args) { 18 19 ClientConfig config = new ClientConfig(); 20 config.connectorProvider(new ApacheConnectorProvider()); 21 22 // config.property(ClientProperties.PROXY_URI, "http://proxy.host.name:8080"); // プロキシの URI 23 config.property(ClientProperties.PROXY_URI, "http://hogehoge:8080"); // プロキシの URI 24 //config.property(ClientProperties.PROXY_USERNAME, "username"); // プロキシ認証のユーザー名(必要なら) 25 //config.property(ClientProperties.PROXY_PASSWORD, "password"); 26 27 28 // For HTTPS 29// System.setProperty("jsse.enableSNIExtension", "false"); 30 31 // POST パラメータ 32 MultivaluedHashMap<String, String> formParams = new MultivaluedHashMap<>(); 33 formParams.putSingle("sentence", "東京ミッドタウンから国立新美術館まで歩いて5分で着きます。"); 34 formParams.putSingle("output", "xml"); 35 36// String result = ClientBuilder.newClient() 37 String result = ClientBuilder.newClient(config) 38 .target("http://jlp.yahooapis.jp") 39 .path("KeyphraseService/V1/extract") 40 .request(MediaType.APPLICATION_XML_TYPE) 41 .header("User-Agent", "Yahoo AppID:hogehoge") 42 .post(Entity.entity(formParams, MediaType.APPLICATION_FORM_URLENCODED_TYPE), String.class); 43 44 // 標準出力にレスポンスを表示 45 System.out.println(result); 46 } 47 48 49}
次のスタックトレースエラーが発生します。
---- top ----------------
Exception in thread "main" javax.ws.rs.ClientErrorException: HTTP 411 Length Required
at org.glassfish.jersey.client.JerseyInvocation.createExceptionForFamily(JerseyInvocation.java:952)
at org.glassfish.jersey.client.JerseyInvocation.convertToException(JerseyInvocation.java:936)
at org.glassfish.jersey.client.JerseyInvocation.translate(JerseyInvocation.java:770)
at org.glassfish.jersey.client.JerseyInvocation.access$500(JerseyInvocation.java:90)
at org.glassfish.jersey.client.JerseyInvocation$2.call(JerseyInvocation.java:671)
at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
at org.glassfish.jersey.internal.Errors.process(Errors.java:228)
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:424)
at org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:667)
at org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:423)
at org.glassfish.jersey.client.JerseyInvocation$Builder.post(JerseyInvocation.java:326)
at com.example.Main3.main(Main3.java:42)
---- end ----------------
プロキシ経由させない書き方に改めてプロキシを挟まない場合は正常に動作しております。
原因の特定が出来ず苦慮しております。
どなたか問題の特定ができますでしょうか。
ご解答頂けます様お願い致します。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。