List of usage examples for org.apache.http.util EntityUtils toString
public static String toString(HttpEntity httpEntity) throws IOException, ParseException
From source file:cn.edu.szjm.support.http.IgnitedHttpResponseImpl.java
public String getResponseBodyAsString() throws IOException { return EntityUtils.toString(entity); }
From source file:org.jwifisd.httpclient.StringResponseHandler.java
@Override public String handleResponse(HttpResponse response) throws IOException { int status = response.getStatusLine().getStatusCode(); if (status >= ByteResponseHandler.START_HTTP_OK_RESPONSE_RANGE && status < ByteResponseHandler.END_HTTP_OK_RESPONSE_RANGE) { HttpEntity entity = response.getEntity(); return entity != null ? EntityUtils.toString(entity) : null; } else {//www .j a v a 2 s .c om throw new ClientProtocolException("Unexpected response status: " + status); } }
From source file:com.citrus.sample.GetBill.java
@Override protected Void doInBackground(Void... params) { HttpClient httpClient = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(billurl); HttpResponse httpResponse;//from w w w .ja v a 2 s . c o m try { httpResponse = httpClient.execute(httpGet); response = new JSONObject(EntityUtils.toString(httpResponse.getEntity())); } catch (IOException e) { e.printStackTrace(); error = "Is your internet working?"; } catch (JSONException e) { e.printStackTrace(); error = "Is your billing url correct?"; } return null; }
From source file:org.artags.android.app.util.http.HttpUtil.java
/** * Post data and attachements// ww w . j a v a 2 s .c o m * @param url The POST url * @param params Parameters * @param files Files * @return The return value * @throws HttpException If an error occurs */ public static String post(String url, HashMap<String, String> params, HashMap<String, File> files) throws HttpException { String ret = ""; try { HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(url); MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); for (String key : files.keySet()) { FileBody bin = new FileBody(files.get(key)); reqEntity.addPart(key, bin); } for (String key : params.keySet()) { String val = params.get(key); reqEntity.addPart(key, new StringBody(val, Charset.forName("UTF-8"))); } post.setEntity(reqEntity); HttpResponse response = client.execute(post); HttpEntity resEntity = response.getEntity(); if (resEntity != null) { ret = EntityUtils.toString(resEntity); Log.i("ARTags:HttpUtil:Post:Response", ret); } //return response; } catch (Exception e) { Log.e("ARTags:HttpUtil", "Error : " + e.getMessage()); throw new HttpException(e.getMessage()); } return ret; }
From source file:dk.ciid.android.infobooth.xml.XMLParser.java
/** * Getting XML from URL making HTTP request * @param url string// w w w .j av a 2 s. co m * */ public String getXmlFromUrl(String url) { String xml = null; try { // defaultHttpClient DefaultHttpClient httpClient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(url); // this line breaks it HttpResponse httpResponse = httpClient.execute(httpPost); HttpEntity httpEntity = httpResponse.getEntity(); xml = EntityUtils.toString(httpEntity); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } // return XML*/ return xml; }
From source file:org.urbantower.j4s.example.simple.SimpleJettyTest.java
@Test public void isJettyServerRunning() throws InterruptedException, IOException { CloseableHttpResponse response = httpclient.execute(new HttpGet("http://localhost:9090")); String body = EntityUtils.toString(response.getEntity()); Assert.assertTrue(body.contains("Powered by Jetty")); }
From source file:org.urbantower.j4s.example.webapp.WebAppTest.java
@Test public void isJettyServerRunning() throws InterruptedException, IOException { CloseableHttpResponse response = httpclient.execute(new HttpGet("http://localhost:9092/webapp/servlet")); String body = EntityUtils.toString(response.getEntity()); Assert.assertTrue(body.contains("Hello Servlet")); }
From source file:com.infojobs.hereismyjob.httpmanager.HttpManager.java
public HttpManager(String str) { try {/* w ww .j a va2 s .co m*/ client = new DefaultHttpClient(); targetHost = new HttpHost(Constants.HOST_NAME, Constants.PORT_NUMBER, Constants.HOST_SCHEME); // Client credentials client.getCredentialsProvider().setCredentials( new AuthScope(targetHost.getHostName(), targetHost.getPort()), new UsernamePasswordCredentials("Aladdin", "open sesame")); // create a GET method that queries some API operation request = new HttpGet(str); // execute the operation response = client.execute(targetHost, request); // print the status and the contents of the response System.out.println(response.getStatusLine()); System.out.println(EntityUtils.toString(response.getEntity())); } catch (MalformedURLException ex) { Constants.showException("Malformed URL exception: " + ex); } catch (IOException ex) { Constants.showException("Input/Output exception: " + ex); } finally { // release any connection resources used by the method client.getConnectionManager().shutdown(); } }
From source file:org.urbantower.j4s.example.servlet.ServletTest.java
@Test public void isJettyServerRunning() throws InterruptedException, IOException { CloseableHttpResponse response = httpclient.execute(new HttpGet("http://localhost:9095/webapp/servlet")); String body = EntityUtils.toString(response.getEntity()); Assert.assertTrue(body.contains("Hello Servlet")); }
From source file:au.edu.anu.portal.portlets.basiclti.support.HttpSupport.java
/** * Make a POST request with the given Map of parameters to be encoded * @param address address to POST to// w w w . j a va 2s . co m * @param params Map of params to use as the form parameters * @return */ public static String doPost(String address, Map<String, String> params) { HttpClient httpclient = new DefaultHttpClient(); try { HttpPost httppost = new HttpPost(address); List<NameValuePair> formparams = new ArrayList<NameValuePair>(); for (Map.Entry<String, String> entry : params.entrySet()) { formparams.add(new BasicNameValuePair(entry.getKey(), entry.getValue())); } UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, HTTP.UTF_8); httppost.setEntity(entity); HttpResponse response = httpclient.execute(httppost); String responseContent = EntityUtils.toString(response.getEntity()); return responseContent; } catch (Exception e) { e.printStackTrace(); } finally { httpclient.getConnectionManager().shutdown(); } return null; }