cz.msebera.android.httpclient.HttpEntity Java Examples
The following examples show how to use
cz.msebera.android.httpclient.HttpEntity.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BaseClass.java From BaiduPanApi-Java with MIT License | 6 votes |
protected CloseableHttpResponse checkLogin(CloseableHttpResponse closeableHttpResponse) throws IOException { HttpEntity bufferedHttpEntity = closeableHttpResponse.getEntity(); String mimeString = ContentType.getOrDefault(bufferedHttpEntity).getMimeType(); if(mimeString.contains("application/json") || mimeString.contains("text/html")) { String content = HttpClientHelper.getResponseString(closeableHttpResponse); System.out.println("checkLogin() content:"+content); try { JSONObject jsonObject = (JSONObject) JSON.parse(content); if (jsonObject.containsKey("errno") && String.valueOf(jsonObject.get("errno")).equals("-6")) { clearCookies(); initiate(); } } catch (Exception e) { } } return closeableHttpResponse; }
Example #2
Source File: TokenRegistryTest.java From pusher-websocket-android with MIT License | 6 votes |
@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 ); }
Example #3
Source File: NetWorkTool.java From FoodOrdering with Apache License 2.0 | 6 votes |
public static String getContent(String url) throws Exception { StringBuilder sb = new StringBuilder(); HttpClient client = new DefaultHttpClient(); HttpParams httpParams = (HttpParams) client.getParams(); // 设置网络超时参数 HttpConnectionParams.setConnectionTimeout(httpParams, 3000); HttpConnectionParams.setSoTimeout(httpParams, 5000); HttpResponse response = client.execute(new HttpGet(url)); HttpEntity entity = response.getEntity(); if (entity != null) { BufferedReader reader = new BufferedReader(new InputStreamReader( entity.getContent(), "GBK"), 8192); String line = null; while ((line = reader.readLine()) != null) { sb.append(line); } reader.close(); } return sb.toString(); }
Example #4
Source File: SubscriptionManagerTest.java From pusher-websocket-android with MIT License | 6 votes |
@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) ); }
Example #5
Source File: SubscriptionManagerTest.java From pusher-websocket-android with MIT License | 5 votes |
@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) ); }
Example #6
Source File: HttpClientHelper.java From BaiduPanApi-Java with MIT License | 5 votes |
public static String getResponseString(CloseableHttpResponse closeableHttpResponse,String charset) throws IOException { HttpEntity bufferedHttpEntity = closeableHttpResponse.getEntity(); if(charset == null){ charset = CHARSET; } return EntityUtils.toString(bufferedHttpEntity, charset); }
Example #7
Source File: MakabaModule.java From Overchan-Android with GNU General Public License v3.0 | 5 votes |
@Override public PostModel[] search(String boardName, String searchRequest, ProgressListener listener, CancellableTask task) throws Exception { String url; HttpRequestModel request; if (searchRequest.startsWith(HASHTAG_PREFIX)) { url = domainUrl + "makaba/makaba.fcgi?task=hashtags&board=" + boardName + "&tag=" + URLEncoder.encode(searchRequest.substring(HASHTAG_PREFIX.length()), "UTF-8") + "&json=1"; request = HttpRequestModel.DEFAULT_GET; } else { url = domainUrl + "makaba/makaba.fcgi"; HttpEntity postEntity = ExtendedMultipartBuilder.create(). addString("task", "search"). addString("board", boardName). addString("find", searchRequest). addString("json", "1"). build(); request = HttpRequestModel.builder().setPOST(postEntity).build(); } JSONObject response = null; try { response = HttpStreamer.getInstance().getJSONObjectFromUrl(url, request, httpClient, listener, task, true); } catch (HttpWrongStatusCodeException e) { checkCloudflareError(e, url); throw e; } if (listener != null) listener.setIndeterminate(); JSONArray posts = response.getJSONArray("posts"); PostModel[] result = new PostModel[posts.length()]; for (int i=0; i<posts.length(); ++i) { result[i] = mapPostModel(posts.getJSONObject(i), boardName); } return result; }
Example #8
Source File: HorochanModule.java From Overchan-Android with GNU General Public License v3.0 | 5 votes |
@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); } }
Example #9
Source File: HttpRequestModel.java From Overchan-Android with GNU General Public License v3.0 | 5 votes |
private HttpRequestModel( int method, boolean checkIfModified, boolean noRedirect, Header[] customHeaders, HttpEntity postEntity, int timeoutValue) { this.method = method; this.checkIfModified = checkIfModified; this.noRedirect = noRedirect; this.customHeaders = customHeaders; this.postEntity = postEntity; this.timeoutValue = timeoutValue; }
Example #10
Source File: TokenRegistryTest.java From pusher-websocket-android with MIT License | 5 votes |
@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 ); }
Example #11
Source File: FeedFragment.java From Instagram-Profile-Downloader with MIT License | 5 votes |
@Override protected String doInBackground(Void... params) { HttpClient httpClient = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(url); try { HttpResponse response = httpClient.execute(httpGet); HttpEntity httpEntity = response.getEntity(); return EntityUtils.toString(httpEntity); } catch (IOException e) { e.printStackTrace(); } return null; }
Example #12
Source File: HttpWebConnection.java From HtmlUnit-Android with Apache License 2.0 | 5 votes |
/** * Downloads the response body. * @param httpResponse the web server's response * @return a wrapper for the downloaded body. * @throws IOException in case of problem reading/saving the body */ protected DownloadedContent downloadResponseBody(final HttpResponse httpResponse) throws IOException { final HttpEntity httpEntity = httpResponse.getEntity(); if (httpEntity == null) { return new DownloadedContent.InMemory(null); } try (InputStream is = httpEntity.getContent()) { return downloadContent(is, webClient_.getOptions().getMaxInMemory()); } }
Example #13
Source File: DownloadProfileImageActivity.java From Instagram-Profile-Downloader with MIT License | 5 votes |
@Override protected String doInBackground(Void... params) { HttpClient httpClient = new DefaultHttpClient(); try { HttpGet httpGet = new HttpGet(url); HttpResponse response = httpClient.execute(httpGet); HttpEntity httpEntity = response.getEntity(); return EntityUtils.toString(httpEntity); } catch (Exception e) { e.printStackTrace(); } return null; }
Example #14
Source File: IntroScreenActivity.java From Instagram-Profile-Downloader with MIT License | 5 votes |
@Override protected String doInBackground(Void... params) { HttpClient httpClient = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(getResources().getString(R.string.get_user_info_url) + token); try { HttpResponse response = httpClient.execute(httpGet); HttpEntity httpEntity = response.getEntity(); return EntityUtils.toString(httpEntity); } catch (IOException e) { e.printStackTrace(); } return null; }
Example #15
Source File: MainActivity.java From Instagram-Profile-Downloader with MIT License | 5 votes |
@Override protected String doInBackground(Void... params) { HttpClient httpClient = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(final_url); try { HttpResponse response = httpClient.execute(httpGet); HttpEntity httpEntity = response.getEntity(); return EntityUtils.toString(httpEntity); } catch (IOException e) { e.printStackTrace(); } return null; }
Example #16
Source File: MainActivity.java From Instagram-Profile-Downloader with MIT License | 5 votes |
@Override protected String doInBackground(Void... params) { HttpClient httpClient = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(url); try { HttpResponse response = httpClient.execute(httpGet); HttpEntity httpEntity = response.getEntity(); return EntityUtils.toString(httpEntity); } catch (IOException e) { e.printStackTrace(); } return null; }
Example #17
Source File: OverviewDialog.java From Instagram-Profile-Downloader with MIT License | 5 votes |
@Override protected String doInBackground(Void... params) { HttpClient httpClient = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(url); try { HttpResponse response = httpClient.execute(httpGet); HttpEntity httpEntity = response.getEntity(); return EntityUtils.toString(httpEntity); } catch (IOException e) { e.printStackTrace(); } return null; }
Example #18
Source File: ProfileFragment.java From Instagram-Profile-Downloader with MIT License | 5 votes |
@Override protected String doInBackground(Void... params) { HttpClient httpClient = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(url); try { HttpResponse response = httpClient.execute(httpGet); HttpEntity httpEntity = response.getEntity(); return EntityUtils.toString(httpEntity); } catch (IOException e) { e.printStackTrace(); } return null; }
Example #19
Source File: SubscriptionManagerTest.java From pusher-websocket-android with MIT License | 4 votes |
@Test public void testSendingListOfSubscriptions() throws IOException { Subscription sub1 = new Subscription("kittens", InterestSubscriptionChange.SUBSCRIBE, listener); Subscription sub2 = new Subscription("donuts", InterestSubscriptionChange.UNSUBSCRIBE, listener); List<Subscription> list = new ArrayList<>(Arrays.asList(sub1, sub2)); subscriptionManager.sendSubscriptions(list); ArgumentCaptor<Subscription> subCaptor = ArgumentCaptor.forClass(Subscription.class); verify(factory).newSubscriptionChangeHandler(sub1); ArgumentCaptor paramsCaptor = ArgumentCaptor.forClass(StringEntity.class); InOrder inOrder = inOrder(client); inOrder.verify(client).post( eq(context), eq("https://nativepushclient-cluster1.pusher.com/client_api/v1/clients/123-456/interests/kittens"), (HttpEntity) paramsCaptor.capture(), eq("application/json"), eq(subscriptionChangeHandler) ); StringEntity params = (StringEntity) paramsCaptor.getValue(); assertEquals( "{\"app_key\":\"super-cool-key\"}", EntityUtils.toString(params) ); ArgumentCaptor<Subscription> subCaptor2 = ArgumentCaptor.forClass(Subscription.class); verify(factory).newSubscriptionChangeHandler(sub2); ArgumentCaptor deleteCaptor = ArgumentCaptor.forClass(StringEntity.class); inOrder.verify(client).delete( eq(context), eq("https://nativepushclient-cluster1.pusher.com/client_api/v1/clients/123-456/interests/donuts"), (HttpEntity) deleteCaptor.capture(), eq("application/json"), eq(subscriptionChangeHandler) ); StringEntity deleteParams = (StringEntity) deleteCaptor.getValue(); assertEquals( "{\"app_key\":\"super-cool-key\"}", EntityUtils.toString(deleteParams) ); }
Example #20
Source File: HttpRequestModel.java From Overchan-Android with GNU General Public License v3.0 | 4 votes |
/** * Установить метод POST * @param postEntity передаваемая сущность (контент) */ public Builder setPOST(HttpEntity postEntity) { this.method = METHOD_POST; this.postEntity = postEntity; return this; }
Example #21
Source File: ExtendedMultipartBuilder.java From Overchan-Android with GNU General Public License v3.0 | 4 votes |
public HttpEntity build() { return new HttpEntityWrapper(builder.build(), listener, task); }
Example #22
Source File: ExtendedMultipartBuilder.java From Overchan-Android with GNU General Public License v3.0 | 4 votes |
private HttpEntityWrapper(HttpEntity entity, ProgressListener listener, CancellableTask task) { this.entity = entity; this.listener = listener; this.task = task; }