本文整理汇总了Java中cz.msebera.android.httpclient.util.EntityUtils.toString方法的典型用法代码示例。如果您正苦于以下问题:Java EntityUtils.toString方法的具体用法?Java EntityUtils.toString怎么用?Java EntityUtils.toString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cz.msebera.android.httpclient.util.EntityUtils
的用法示例。
在下文中一共展示了EntityUtils.toString方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: get
import cz.msebera.android.httpclient.util.EntityUtils; //导入方法依赖的package包/类
public static Hostplace get(String ip) throws Exception {
HttpGet httppost = new HttpGet(Geocode.url + "/" + ip);
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(httppost);
// StatusLine stat = response.getStatusLine();
int status = response.getStatusLine().getStatusCode();
if (status == 200) {
HttpEntity entity = response.getEntity();
String data = EntityUtils.toString(entity);
JSONObject json = new JSONObject(data);
if (json.getString("status").equals("fail"))
throw new Exception();
Hostplace hostplace = Hostplace.getJson(json);
return hostplace;
}
throw new Exception();
}
示例2: getBlock
import cz.msebera.android.httpclient.util.EntityUtils; //导入方法依赖的package包/类
public static Block getBlock(String blockhash) throws Exception {
HttpGet httppost = new HttpGet(Insight.url + "/block/" + blockhash);
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(httppost);
// StatusLine stat = response.getStatusLine();
int status = response.getStatusLine().getStatusCode();
if (status == 200) {
HttpEntity entity = response.getEntity();
String data = EntityUtils.toString(entity);
JSONObject json = new JSONObject(data);
Block block = Block.getJson(json);
return block;
}
throw new Exception();
}
示例3: getBlockHash
import cz.msebera.android.httpclient.util.EntityUtils; //导入方法依赖的package包/类
public static String getBlockHash(String height) throws Exception {
HttpGet httppost = new HttpGet(Insight.url + "/block-index/" + height);
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(httppost);
// StatusLine stat = response.getStatusLine();
int status = response.getStatusLine().getStatusCode();
if (status == 200) {
HttpEntity entity = response.getEntity();
String data = EntityUtils.toString(entity);
JSONObject json = new JSONObject(data);
String hash = json.getString("blockHash");
return hash;
}
throw new Exception();
}
示例4: getTx
import cz.msebera.android.httpclient.util.EntityUtils; //导入方法依赖的package包/类
public static Tx getTx(String hash) throws Exception {
HttpGet httppost = new HttpGet(Insight.url + "/tx/" + hash);
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(httppost);
// StatusLine stat = response.getStatusLine();
int status = response.getStatusLine().getStatusCode();
if (status == 200) {
HttpEntity entity = response.getEntity();
String data = EntityUtils.toString(entity);
JSONObject json = new JSONObject(data);
Tx tx = Tx.getJson(json);
return tx;
}
throw new Exception();
}
示例5: performHttpGet
import cz.msebera.android.httpclient.util.EntityUtils; //导入方法依赖的package包/类
public void performHttpGet(String uri, HttpResponseCallback callback) {
try {
HttpGet get = new HttpGet(new URI(uri));
CloseableHttpResponse response = client.execute(get);
int status = response.getStatusLine().getStatusCode();
try {
HttpEntity entity = response.getEntity();
String json = EntityUtils.toString(entity);
EntityUtils.consume(entity);
callback.onHttpResponse(status, json);
} finally {
response.close();
}
} catch (IOException | URISyntaxException e) {
callback.onException(e);
}
}
示例6: execute
import cz.msebera.android.httpclient.util.EntityUtils; //导入方法依赖的package包/类
private JSONObject execute(HttpPost request, JSONObject payload) throws IOException, NetworkException, JSONException {
setPayloadXsrf(payload);
request.setEntity(new ByteArrayEntity(payload.toString().getBytes()));
authenticateRequest(request);
HttpResponse resp = client.execute(request, httpContext);
StatusLine sl = resp.getStatusLine();
if (sl.getStatusCode() != 200) throw new NetworkException(sl);
return new JSONObject(EntityUtils.toString(resp.getEntity(), Charset.forName("UTF-8")));
}
示例7: getHtmlConsolePage
import cz.msebera.android.httpclient.util.EntityUtils; //导入方法依赖的package包/类
private static String getHtmlConsolePage(String dev_acc, CookieStore cookieStore) throws IOException, NetworkException {
HttpGet get = new HttpGet(Utils.DEVELOPER_CONSOLE_URL + "?dev_acc=" + dev_acc);
HttpClient client = HttpClientBuilder.create().setDefaultCookieStore(cookieStore).build();
HttpResponse resp = client.execute(get);
StatusLine sl = resp.getStatusLine();
if (sl.getStatusCode() != 200) throw new NetworkException(sl);
return EntityUtils.toString(resp.getEntity(), Charset.forName("UTF-8"));
}
示例8: getResponseString
import cz.msebera.android.httpclient.util.EntityUtils; //导入方法依赖的package包/类
public static String getResponseString(CloseableHttpResponse closeableHttpResponse,String charset) throws IOException {
HttpEntity bufferedHttpEntity = closeableHttpResponse.getEntity();
if(charset == null){
charset = CHARSET;
}
return EntityUtils.toString(bufferedHttpEntity, charset);
}