本文整理汇总了Java中cz.msebera.android.httpclient.util.EntityUtils类的典型用法代码示例。如果您正苦于以下问题:Java EntityUtils类的具体用法?Java EntityUtils怎么用?Java EntityUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EntityUtils类属于cz.msebera.android.httpclient.util包,在下文中一共展示了EntityUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: performBinaryHttpGet
import cz.msebera.android.httpclient.util.EntityUtils; //导入依赖的package包/类
public void performBinaryHttpGet(String uri, BinaryHttpResponseCallback callback) {
try {
HttpGet get = new HttpGet(new URI(uri));
CloseableHttpResponse response = client.execute(get);
int status = response.getStatusLine().getStatusCode();
try {
HttpEntity entity = response.getEntity();
callback.onHttpResponse(status, entity.getContent());
EntityUtils.consume(entity);
} finally {
response.close();
}
} catch (IOException | URISyntaxException e) {
callback.onException(e);
}
}
示例7: testSubscribe
import cz.msebera.android.httpclient.util.EntityUtils; //导入依赖的package包/类
@Test
public void testSubscribe() throws IOException {
Subscription sub = new Subscription("donuts",
InterestSubscriptionChange.SUBSCRIBE,
listener);
subscriptionManager.sendSubscription(sub);
ArgumentCaptor<Subscription> subCaptor = ArgumentCaptor.forClass(Subscription.class);
verify(factory).newSubscriptionChangeHandler(sub);
ArgumentCaptor paramsCaptor = ArgumentCaptor.forClass(StringEntity.class);
verify(client).post(
eq(context),
eq("https://nativepushclient-cluster1.pusher.com/client_api/v1/clients/123-456/interests/donuts"),
(HttpEntity) paramsCaptor.capture(),
eq("application/json"),
eq(subscriptionChangeHandler)
);
StringEntity params = (StringEntity) paramsCaptor.getValue();
assertEquals(
"{\"app_key\":\"super-cool-key\"}",
EntityUtils.toString(params)
);
}
示例8: receiveUploadsWhenNoCachedId
import cz.msebera.android.httpclient.util.EntityUtils; //导入依赖的package包/类
@Test
public void receiveUploadsWhenNoCachedId() throws Exception {
tokenRegistry.receive("mysuperspecialfcmtoken");
verify(factory).newTokenUploadHandler(context, stack);
ArgumentCaptor paramsCaptor = ArgumentCaptor.forClass(StringEntity.class);
verify(client).post(
eq(context),
eq("https://nativepushclient-cluster1.pusher.com/client_api/v1/clients"),
(HttpEntity) paramsCaptor.capture(),
eq("application/json"),
eq(tokenUploadHandler)
);
// test proper params sent
HttpEntity params = (HttpEntity) paramsCaptor.getValue();
JSONAssert.assertEquals(
EntityUtils.toString(params),
"{\"platform_type\":\"fcm\",\"token\":\"mysuperspecialfcmtoken\",\"app_key\":\"superkey\"}",
true
);
}
示例9: 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")));
}
示例10: 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"));
}
示例11: testUnsubscribe
import cz.msebera.android.httpclient.util.EntityUtils; //导入依赖的package包/类
@Test
public void testUnsubscribe() throws IOException {
Subscription subscription = new Subscription(
"donuts",
InterestSubscriptionChange.UNSUBSCRIBE,
listener);
subscriptionManager.sendSubscription(subscription);
ArgumentCaptor<Subscription> subCaptor = ArgumentCaptor.forClass(Subscription.class);
verify(factory).newSubscriptionChangeHandler(
subscription
);
ArgumentCaptor paramsCaptor = ArgumentCaptor.forClass(StringEntity.class);
verify(client).delete(
eq(context),
eq("https://nativepushclient-cluster1.pusher.com/client_api/v1/clients/123-456/interests/donuts"),
(HttpEntity) paramsCaptor.capture(),
eq("application/json"),
eq(subscriptionChangeHandler)
);
StringEntity params = (StringEntity) paramsCaptor.getValue();
assertEquals(
"{\"app_key\":\"super-cool-key\"}",
EntityUtils.toString(params)
);
}
示例12: receivesUpdatesWhenCachedId
import cz.msebera.android.httpclient.util.EntityUtils; //导入依赖的package包/类
@Test
public void receivesUpdatesWhenCachedId() throws Exception {
PreferenceManager.
getDefaultSharedPreferences(context).
edit().
putString("__pusher__client__key__fcm__superkey", "this-is-the-client-id")
.apply();
tokenRegistry.receive("woot-token-woot");
ArgumentCaptor paramsCaptor = ArgumentCaptor.forClass(StringEntity.class);
verify(factory).newTokenUpdateHandler(
eq("this-is-the-client-id"),
(StringEntity) paramsCaptor.capture(),
eq(context),
eq(stack),
eq(tokenRegistry)
);
StringEntity sentParams = (StringEntity) paramsCaptor.getValue();
verify(client).put(
eq(context),
eq("https://nativepushclient-cluster1.pusher.com/client_api/v1/clients/this-is-the-client-id/token"),
eq(sentParams),
eq("application/json"),
eq(tokenUpdateHandler)
);
JSONAssert.assertEquals(EntityUtils.toString((HttpEntity) paramsCaptor.getValue()),
"{\"platform_type\":\"fcm\",\"token\":\"woot-token-woot\",\"app_key\":\"superkey\"}",
true
);
}
示例13: deletePost
import cz.msebera.android.httpclient.util.EntityUtils; //导入依赖的package包/类
@Override
public String deletePost(DeletePostModel model, ProgressListener listener, CancellableTask task) throws Exception {
String url = getUsingUrl(true) + "v1/posts/" + model.postNumber;
HttpEntity entity = ExtendedMultipartBuilder.create().setDelegates(listener, task).addString("password", model.password).build();
HttpUriRequest request = null;
HttpResponse response = null;
HttpEntity responseEntity = null;
try {
request = RequestBuilder.delete().setUri(url).setEntity(entity).build();
response = httpClient.execute(request);
StatusLine status = response.getStatusLine();
switch (status.getStatusCode()) {
case 200:
return null;
case 400:
responseEntity = response.getEntity();
InputStream stream = IOUtils.modifyInputStream(responseEntity.getContent(), null, task);
JSONObject json = new JSONObject(new JSONTokener(new BufferedReader(new InputStreamReader(stream))));
throw new Exception(json.getString("message"));
default:
throw new Exception(status.getStatusCode() + " - " + status.getReasonPhrase());
}
} finally {
try { if (request != null) request.abort(); } catch (Exception e) {}
EntityUtils.consumeQuietly(responseEntity);
if (response != null && response instanceof Closeable) IOUtils.closeQuietly((Closeable) response);
}
}
示例14: 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);
}
示例15: extractUrls
import cz.msebera.android.httpclient.util.EntityUtils; //导入依赖的package包/类
public static String extractUrls(HttpResponse response) {
String found = null;
try {
Scanner scan;
Header contentEncoding = response
.getFirstHeader("Content-Encoding");
if (contentEncoding != null
&& contentEncoding.getValue().equalsIgnoreCase("gzip")) {
scan = new Scanner(new GZIPInputStream(response.getEntity()
.getContent()));
} else {
scan = new Scanner(response.getEntity().getContent());
}
found = scan.findWithinHorizon(url_match_pattern, 0);
if (null != found) {
Matcher m = url_match_pattern.matcher(found);
if (m.matches())
found = m.group(1);
}
scan.close();
EntityUtils.consume(response.getEntity());
} catch (Throwable t) {
Log.e(LOG_TAG, "Error Occurred", t);
}
return found;
}