http クライアント関連のクラスがあるため、多くの廃止予定があります。
ここに私のコード:
this.httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet(url);
HttpResponse response = this.httpclient.execute(httpget);
HttpEntity entity = response.getEntity();
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode == HttpStatus.SC_OK) {
BufferedReader reader = new BufferedReader(
new InputStreamReader(entity.getContent(),
EntityUtils.getContentCharSet(entity))
);
String line = null;
Matcher matcher = null;
while ((line = reader.readLine()) != null) {
matcher = matcher == null ? this.resultPattern
.matcher(line) : matcher.reset(line);
if (matcher.matches()) {
httpget.abort();
return Double.parseDouble(matcher.group(1));
}
}
httpget.abort();
throw new MyException("Could not find ["
+ resultPattern.toString() + "] in response to [" + url
+ "]");
} else {
if (entity != null) {
entity.consumeContent();
}
throw new MyException("Got [" + statusCode
+ "] in response to [" + url + "]");
}
DefaultHttpClient
非推奨非
HttpResponse
推奨 非
HttpEntity
推奨
ネイティブ ライブラリを使用して修正するにはどうすればよいですか? 私は検索し、何人かの人々をHttpClient
使用しHttpClientBuilder
ましたが、追加のライブラリが必要であり、さらに、他の非推奨の問題を修正する方法がわかりません。
私を助けることができるプログラマーはいますか?この大規模な非推奨の理由は何ですか?
を使用する必要があるHttpURLConnection
ようですが、コードをこれらのライブラリに移行する方法がわかりません。