Example usage for org.apache.http.impl.client DefaultHttpClient execute

List of usage examples for org.apache.http.impl.client DefaultHttpClient execute

Introduction

In this page you can find the example usage for org.apache.http.impl.client DefaultHttpClient execute.

Prototype

public CloseableHttpResponse execute(final HttpUriRequest request) throws IOException, ClientProtocolException 

Source Link

Usage

From source file:com.ssy.havefunweb.util.WeixinUtil.java

public static JSONObject doPostStr(String url, String outStr) throws UnsupportedEncodingException, IOException {
    DefaultHttpClient httpClient = new DefaultHttpClient();
    HttpPost httpPost = new HttpPost(url);
    httpPost.setEntity(new StringEntity(outStr, "UTF-8"));
    HttpResponse response = httpClient.execute(httpPost);
    String result = EntityUtils.toString(response.getEntity(), "UTF-8");
    JSONObject jsonObject = JSONObject.fromObject(result);
    return jsonObject;
}

From source file:com.github.ajasmin.telususageandroidwidget.TelusReportFetcher.java

private static void fetchLogOutPage(DefaultHttpClient httpclient) throws IOException {
    final String url = "https://mobile.telus.com/logout.htm";
    HttpGet httpGet = new HttpGet(url);

    HttpResponse response = httpclient.execute(httpGet);
    HttpEntity responseEntity = response.getEntity();
    // fetch the contents
    responseEntity.getContent().close();
}

From source file:com.mono.applink.Facebook.java

public static HttpResponse simpleHttp(HttpGet HttpGet) {
    HttpResponse response = null;/*from  w ww .  j a v  a  2 s .  c om*/

    DefaultHttpClient client = new DefaultHttpClient();
    try {
        response = client.execute(HttpGet);

    } catch (ClientProtocolException e) {
    } catch (IOException e) {
    }
    return response;
}

From source file:org.opf_labs.fmts.fidget.droid.PRONOMSigGenerator.java

/**
 * @param sigdef//from w  ww .j a v a 2 s .  com
 */
public static void generatePRONOMSigFile(SigDefSubmission sigdef) {
    DefaultHttpClient httpclient = new DefaultHttpClient();
    try {

        HttpPost httpost = new HttpPost(SERVICE_URL);

        httpost.setEntity(new UrlEncodedFormEntity(createNameValuePairs(sigdef), Consts.UTF_8));

        HttpResponse response = httpclient.execute(httpost);
        HttpEntity entity = response.getEntity();

        // Print out:
        IOUtils.copy(entity.getContent(), System.out);
        // Finish up:
        EntityUtils.consume(entity);

    } catch (ClientProtocolException e) {
        e.printStackTrace();

    } catch (IOException e) {
        e.printStackTrace();

    } finally {
        // When HttpClient instance is no longer needed,
        // shut down the connection manager to ensure
        // immediate deallocation of all system resources
        httpclient.getConnectionManager().shutdown();
    }
}

From source file:wordGame.Util.WebUtil.java

public static Board GetBoardFromServer(String boardID) {
    DefaultHttpClient httpclient = new DefaultHttpClient();
    HttpGet getMethod = new HttpGet(WEBGETBOARD + boardID);
    Scanner fileScanner = null;/*from   w  ww.  ja  v  a 2s  . co m*/
    String boardString = null;
    try {
        HttpResponse response = httpclient.execute(getMethod);
        HttpEntity responseEntity = response.getEntity();

        if (responseEntity != null) {
            fileScanner = new Scanner(new BufferedReader(new InputStreamReader(responseEntity.getContent())));
            while (fileScanner.hasNext()) {
                boardString = fileScanner.next();
                return BoardGenerator.generateCubesFromWebString(boardString);
            }
        }
    } catch (IOException e) {
        return null;
    }
    return null;

}

From source file:middleware.HTTPRequest.java

public static void doPostReplica() throws UnsupportedEncodingException, IOException {
    String url = "http://localhost:8084/MVIv2/webapi/rr/replicar";
    DefaultHttpClient httpClient = new DefaultHttpClient();
    HttpPost postRequest = new HttpPost(url);

    HttpResponse response = httpClient.execute(postRequest);

    if (response.getStatusLine().getStatusCode() != 200) {
        throw new RuntimeException("ERROR AL REPLICAR DEL TIPO: " + response.getStatusLine().getStatusCode());
    }//from  w  w  w.j a v  a2  s.co m

    httpClient.getConnectionManager().shutdown();

}

From source file:middleware.HTTPRequest.java

public static void doPostRestaura() throws UnsupportedEncodingException, IOException {
    String url = "http://localhost:8084/MVIv2/webapi/rr/restaurar";
    DefaultHttpClient httpClient = new DefaultHttpClient();
    HttpPost postRequest = new HttpPost(url);

    HttpResponse response = httpClient.execute(postRequest);

    if (response.getStatusLine().getStatusCode() != 200) {
        throw new RuntimeException("ERROR AL RESTAURAR DEL TIPO: " + response.getStatusLine().getStatusCode());
    }// w w w  .j a v  a2  s  .  c  o m

    httpClient.getConnectionManager().shutdown();

}

From source file:edu.harvard.i2b2.eclipse.plugins.metadataLoader.util.FileUtil.java

public static void download(String workingDir, String URL, String filename) throws IOException {
    workingDir = workingDir + filename;// w w  w  .  ja va2  s . c o  m

    DefaultHttpClient httpclient = new DefaultHttpClient();
    HttpGet httpget = new HttpGet(URL);

    HttpResponse response = httpclient.execute(httpget);

    //      System.out.println(response.getStatusLine());
    HttpEntity entity = response.getEntity();
    if (entity != null) {

        InputStream instream = entity.getContent();

        try {
            BufferedInputStream bis = new BufferedInputStream(instream);
            BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(new File(workingDir)));
            int inByte;
            while ((inByte = bis.read()) != -1) {
                bos.write(inByte);
            }
            bis.close();
            bos.close();
            //       unzip("ICD10.zip");
        } catch (IOException ex) {
            throw ex;
        } catch (RuntimeException ex) {
            httpget.abort();
            throw ex;
        } finally {
            instream.close();
        }
        httpclient.getConnectionManager().shutdown();

    }
}

From source file:com.lambdasoup.panda.PandaHttp.java

static String get(String url, Map<String, String> params, Properties properties) {
    Map<String, String> sParams = signedParams("GET", url, params, properties);
    String flattenParams = canonicalQueryString(sParams);
    String requestUrl = "http://" + properties.getProperty("api-host") + ":80/v2" + url + "?" + flattenParams;
    HttpGet httpGet = new HttpGet(requestUrl);
    DefaultHttpClient httpclient = new DefaultHttpClient();

    String stringResponse = null;

    try {/*from  w  w w . j av  a  2s. c  o  m*/
        HttpResponse response = httpclient.execute(httpGet);
        stringResponse = EntityUtils.toString(response.getEntity());
    } catch (IOException e) {
        e.printStackTrace();
    }

    return stringResponse;
}

From source file:com.thecorpora.qbo.androidapk.MjpegInputStream.java

public static MjpegInputStream read(String url, Cookie cookie) {
    HttpResponse res;/*from ww  w. j av  a 2s  . co m*/
    DefaultHttpClient httpclient = new DefaultHttpClient();

    HttpGet get = new HttpGet(url);
    Log.d("COOKIE", cookie.getValue());
    get.setHeader("Cookie", "session_id=" + cookie.getValue());

    try {
        res = httpclient.execute(get);
        return new MjpegInputStream(res.getEntity().getContent());
    } catch (ClientProtocolException e) {
    } catch (IOException e) {
    }
    return null;
}