javaでhttpclientを使い、proxy経由でアクセスしたいのですが下記エラーが解消できません。
どうすれば解消できるでしょうか。
【実行環境】
java8
org.apache.httpcomponents:httpclient v4.3
プロキシサーバーはherokuのfixieアドオンを使用
サンプルとして下記ページを参照
apacheサンプル
※fixieのサンプルも試したがうまくいきませんでした。
【実行コード】
java
1PROXY_HOST = "velodrome.usefixie.com";//fixieのホスト名 2 3 public void test() throws ClientProtocolException, IOException { 4 CredentialsProvider credsProvider = new BasicCredentialsProvider(); 5 credsProvider.setCredentials( 6 new AuthScope(PROXY_HOST, 80), 7 new UsernamePasswordCredentials(PROXY_USER, PROXY_PASSWORD)); 8 CloseableHttpClient httpclient = HttpClients.custom() 9 .setDefaultCredentialsProvider(credsProvider).build(); 10 try { 11 HttpHost target = new HttpHost("www.verisign.com", 443, "https"); 12 HttpHost proxy = new HttpHost(PROXY_HOST, 80); 13 14 RequestConfig config = RequestConfig.custom() 15 .setProxy(proxy) 16 .build(); 17 HttpGet httpget = new HttpGet("/"); 18 httpget.setConfig(config); 19 20 System.out.println("Executing request " + httpget.getRequestLine() + " to " + target + " via " + proxy); 21 22 CloseableHttpResponse response = httpclient.execute(target, httpget); 23 try { 24 System.out.println("----------------------------------------"); 25 System.out.println(response.getStatusLine()); 26 EntityUtils.consume(response.getEntity()); 27 } finally { 28 response.close(); 29 } 30 } finally { 31 httpclient.close(); 32 } 33
【発生エラー】
java
12016-05-19 22:06:20.593 INFO 2350 --- [nio-8080-exec-1] o.apache.http.impl.execchain.RetryExec : I/O exception (org.apache.http.NoHttpResponseException) caught when processing request: The target server failed to respond 22016-05-19 22:06:20.594 INFO 2350 --- [nio-8080-exec-1] o.apache.http.impl.execchain.RetryExec : Retrying request 32016-05-19 22:06:20.963 INFO 2350 --- [nio-8080-exec-1] o.apache.http.impl.execchain.RetryExec : I/O exception (org.apache.http.NoHttpResponseException) caught when processing request: The target server failed to respond 42016-05-19 22:06:20.963 INFO 2350 --- [nio-8080-exec-1] o.apache.http.impl.execchain.RetryExec : Retrying request 52016-05-19 22:06:21.321 INFO 2350 --- [nio-8080-exec-1] o.apache.http.impl.execchain.RetryExec : I/O exception (org.apache.http.NoHttpResponseException) caught when processing request: The target server failed to respond 62016-05-19 22:06:21.322 INFO 2350 --- [nio-8080-exec-1] o.apache.http.impl.execchain.RetryExec : Retrying request 72016-05-19 22:06:21.661 ERROR 2350 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception 8 9org.apache.http.NoHttpResponseException: The target server failed to respond 10 at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:143) ~[httpclient-4.3.jar:4.3] 11 at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:57) ~[httpclient-4.3.jar:4.3] 12 at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:261) ~[httpcore-4.4.4.jar:4.4.4] 13以後省略
以上、よろしくお願いします。
あなたの回答
tips
プレビュー