11
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【Java】Basic認証付きproxy経由のHTTPリクエスト方法

Last updated at Posted at 2014-10-15

#Java8でproxy経由

HttpReq.java
HttpHost proxy = new HttpHost(Host, port);
RequestConfig requestConfig = RequestConfig.custom().setProxy(proxy).build();
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(new AuthScope(host, port), new UsernamePasswordCredentials(userID,passwd));
HttpClient httpClient = HttpClientBuilder.create()
		         .setDefaultRequestConfig(requestConfig)
		         .setDefaultCredentialsProvider(credsProvider)
		         .build();
String urlString = URL;
HttpPost post = new HttpPost(urlString);
post.setHeader("Content-Type", "text/html; charset=Shift_JIS");
final HttpResponse res = httpClient.execute(post);
HttpEntity httpEntity = res.getEntity();
log.debug("HTTP_REQ=>" + EntityUtils.toString(httpEntity));

こんな感じで長すぎワロタ
もっと短くできそうだと思うんだけどね…

Diff10/21
直したら綺麗になった!キータちゃんすごす

11
13
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?