Commit e7c4e436 authored by jim's avatar jim

tran

parent d8296e81
package com.edgec.browserbackend.common.utils;
import org.apache.commons.io.Charsets;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
......@@ -12,12 +13,11 @@ import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Trans {
private final Logger logger = LoggerFactory.getLogger(Trans.class);
......@@ -50,7 +50,7 @@ public class Trans {
*/
public static void main(String[] args) {
String url = "http://free.ipwhois.io/json/";
Trans trans = new Trans("23.105.2.118", "uE5LkzM81UhUaA1");
Trans trans = new Trans("112.74.47.217", 20001, "fangguanlianbrowser", "5D753F36QKqIaA1");
String rs = trans.get(url);
System.out.println(rs);
}
......@@ -84,17 +84,7 @@ public class Trans {
HttpResponse response = client.execute(httpGet);
HttpEntity entry = response.getEntity();
if (entry != null) {
InputStreamReader is = new InputStreamReader(entry.getContent());
BufferedReader br = new BufferedReader(is);
String str = null;
while ((str = br.readLine()) != null) {
sb.append(str.trim());
}
br.close();
}
return sb.toString();
return EntityUtils.toString(entry, Charsets.UTF_8);
} catch (ClientProtocolException e) {
logger.error(e.getMessage(), e);
return "";
......@@ -106,6 +96,11 @@ public class Trans {
return "";
} finally {
httpGet.releaseConnection();
try {
client.close();
} catch (IOException e) {
logger.error("fail to close connection", e);
}
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment