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

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

Introduction

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

Prototype

public DefaultHttpClient() 

Source Link

Usage

From source file:cardgametrackercs319.DBConnectionManager.java

public static String registerUserInfo(String id, String name, String pwd)
        throws UnsupportedEncodingException, IOException {
    HttpClient client = new DefaultHttpClient();
    HttpPost post = new HttpPost("http://ozymaxx.net/cs319/register_user.php");

    post.setHeader("User Agent", USER_AGENT);
    ArrayList<NameValuePair> urlParameters = new ArrayList<NameValuePair>();
    urlParameters.add(new BasicNameValuePair("id", id));
    urlParameters.add(new BasicNameValuePair("pname", name));
    urlParameters.add(new BasicNameValuePair("pwd", pwd));

    post.setEntity(new UrlEncodedFormEntity(urlParameters));

    HttpResponse response = client.execute(post);
    BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
    StringBuffer result = new StringBuffer();
    String res = "";

    while ((res = reader.readLine()) != null) {
        result.append(res);/*from  w  ww  .  j  a  va2 s.co  m*/
    }

    return result.toString();
}

From source file:com.tedx.webservices.WebServices.java

public static JSONArray SendHttpPostArray(String URL, JSONObject jsonObjSend) {
    try {/*  w  w  w. j  av  a 2  s.  co  m*/
        DefaultHttpClient httpclient = new DefaultHttpClient();
        HttpPost httpPostRequest = new HttpPost(URL);

        StringEntity se;
        se = new StringEntity(jsonObjSend.toString());

        // Set HTTP parameters
        httpPostRequest.setEntity(se);
        httpPostRequest.setHeader("Accept", "application/json");
        httpPostRequest.setHeader("Content-type", "application/json");
        //httpPostRequest.setHeader("Accept-Encoding", "gzip"); // only set this parameter if you would like to use gzip compression

        long t = System.currentTimeMillis();
        HttpResponse response = (HttpResponse) httpclient.execute(httpPostRequest);
        Log.i(TAG, "HTTPResponse received in [" + (System.currentTimeMillis() - t) + "ms]");

        // Get hold of the response entity (-> the data):
        HttpEntity entity = response.getEntity();

        if (entity != null) {
            // Read the content stream
            InputStream instream = entity.getContent();
            Header contentEncoding = response.getFirstHeader("Content-Encoding");
            if (contentEncoding != null && contentEncoding.getValue().equalsIgnoreCase("gzip")) {
                instream = new GZIPInputStream(instream);
            }

            // convert content stream to a String
            String resultString = convertStreamToString(instream);
            instream.close();

            // Transform the String into a JSONObject
            JSONArray jsonObjRecv = new JSONArray(resultString);
            // Raw DEBUG output of our received JSON object:
            Log.i(TAG, "<jsonobject>\n" + jsonObjRecv.toString() + "\n</jsonobject>");

            return jsonObjRecv;
        }
    } catch (Exception e) {
        // More about HTTP exception handling in another tutorial.
        // For now we just print the stack trace.
        e.printStackTrace();
    }
    return null;
}

From source file:test.java.ecplugins.weblogic.TestUtils.java

public static void setResourceAndWorkspace(String resourceName, String workspaceName, String pluginName)
        throws Exception {

    props = getProperties();/*from   w  w  w  . j  a  va2 s. c  om*/
    HttpClient httpClient = new DefaultHttpClient();
    JSONObject jo = new JSONObject();
    jo.put("projectName", pluginName);
    jo.put("resourceName", resourceName);
    jo.put("workspaceName", workspaceName);

    HttpPut httpPutRequest = new HttpPut("http://" + props.getProperty(StringConstants.COMMANDER_SERVER)
            + ":8000/rest/v1.0/projects/" + pluginName);

    String encoding = new String(
            org.apache.commons.codec.binary.Base64.encodeBase64(org.apache.commons.codec.binary.StringUtils
                    .getBytesUtf8(props.getProperty(StringConstants.COMMANDER_USER) + ":"
                            + props.getProperty(StringConstants.COMMANDER_PASSWORD))));
    StringEntity input = new StringEntity(jo.toString());

    input.setContentType("application/json");
    httpPutRequest.setEntity(input);
    httpPutRequest.setHeader("Authorization", "Basic " + encoding);
    HttpResponse httpResponse = httpClient.execute(httpPutRequest);

    if (httpResponse.getStatusLine().getStatusCode() >= 400) {
        throw new RuntimeException("Failed to set resource  " + resourceName + " to project " + pluginName);
    }
    System.out.println("Set the resource as " + resourceName + " and workspace as " + workspaceName
            + " successfully for " + pluginName);
}

From source file:br.com.estudogrupo.online.DicionarioOnline03.java

@Override
public void run() {
    HttpClient client = new DefaultHttpClient();
    HttpPost post = new HttpPost("http://www.cloudcracker.net/index.php");
    try {/*  w w w . ja v  a 2s  .  c o  m*/
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
        nameValuePairs.add(new BasicNameValuePair("inputbox", getRecebe()));
        nameValuePairs.add(new BasicNameValuePair("submit", "Crack+MD5+Hash"));
        post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        HttpResponse response = client.execute(post);
        BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
        String line = "";
        while ((line = rd.readLine().trim()) != null) {

            if (line.startsWith("Word:")) {
                String key = line.substring(96);
                System.out.println("Senha  : " + key.replace("\"", "").replace("/>", ""));
                System.exit(0);
            }
        }
    } catch (IOException e) {
        e.printStackTrace();

    } catch (NullPointerException e) {

    }

}

From source file:com.peteydog7.mcstreamnotifier.twitch.Http.java

public static String sendApiGet(String urlPath, List<NameValuePair> urlParameters) throws Exception {

    if (Config.Value.AUTH_TOKEN != "none") {
        urlParameters.add(new BasicNameValuePair("oauth_token", Config.Value.AUTH_TOKEN));
    }//from  www . ja v a2  s  . c  o m

    URIBuilder uriBuilder = new URIBuilder();

    uriBuilder.setScheme("https");
    uriBuilder.setHost(Twitch.API_BASE);
    uriBuilder.setPath(urlPath);
    uriBuilder.setParameters(urlParameters);

    URI url = uriBuilder.build();

    HttpClient client = new DefaultHttpClient();
    HttpGet request = new HttpGet(url);

    // add request header
    request.addHeader("User-Agent", USER_AGENT);

    request.addHeader("client_id", Twitch.CLIENT_ID);
    request.addHeader("Accept", Twitch.API_VERSION);

    HttpResponse response = client.execute(request);

    LogHelper.info("Sending 'GET' request to URL : " + url);
    LogHelper.info("Response Code : " + response.getStatusLine().getStatusCode());

    if (response.getStatusLine().getStatusCode() != 200) {
        ThreadManager.restartThreadTwitch();
        return null;
    }

    BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));

    StringBuilder result = new StringBuilder();
    String line;
    while ((line = rd.readLine()) != null) {
        result.append(line);
    }

    return result.toString();

}

From source file:org.eclipse.jetty.client.api.ApacheUsage.java

@Test
public void test() {
    HttpClient client = new DefaultHttpClient();
}

From source file:com.buddycloud.friendfinder.HttpUtils.java

public static void post(String URL, Map<String, String> params) throws Exception {
    HttpClient client = new DefaultHttpClient();
    HttpPost httpPost = new HttpPost(URL);
    HttpParams httpParams = new BasicHttpParams();
    for (Entry<String, String> entryParam : params.entrySet()) {
        httpParams.setParameter(entryParam.getKey(), entryParam.getValue());
    }/*  w ww  . ja  va2s  .  c  o  m*/
    httpPost.setParams(httpParams);
    client.execute(httpPost);
}

From source file:WSpatern.getFileSecuirty.java

public void getSecuirty(String token, String id) {
    try {//from  w ww  .jav  a 2 s  . c  om
        DefaultHttpClient client = new DefaultHttpClient();
        HttpGet get = new HttpGet(
                "http://documenta-dms.com/DMSWS/api/v1/attribute/" + token + "/file_security_by_id/" + id);
        HttpResponse response = client.execute(get);
        BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
        String line = "";
        while ((line = rd.readLine()) != null) {

            System.out.println(line);
            parseXML(line);

        }
    } catch (IOException ex) {
        Logger.getLogger(ValidTokenWS.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.qihoo.permmgr.util.d.java

public static String a(String paramString, int paramInt) {
    try {//from   w w w .  ja  v a  2  s  .co  m
        HttpGet localHttpGet = new HttpGet(paramString);
        DefaultHttpClient localDefaultHttpClient = new DefaultHttpClient();
        localDefaultHttpClient.getParams().setParameter("http.connection.timeout", Integer.valueOf(paramInt));
        localDefaultHttpClient.getParams().setParameter("http.socket.timeout", Integer.valueOf(paramInt));
        HttpResponse localHttpResponse = localDefaultHttpClient.execute(localHttpGet);
        if (200 == localHttpResponse.getStatusLine().getStatusCode()) {
            String str = EntityUtils.toString(localHttpResponse.getEntity());
            return str;
        }
    } catch (Exception localException) {
        localException.printStackTrace();
    }
    return null;
}

From source file:com.storageroomapp.client.util.Http.java

/**
 * GET the payload for the given URL as a String
 * /*from w w w  . j  av a 2 s .c  om*/
 * @param url a String url
 * @return a String if successful, null otherwise
 */
static public String getAsString(String url) {
    String body = null;
    try {
        HttpClient httpclient = new DefaultHttpClient();
        HttpGet httpget = new HttpGet(url);
        HttpResponse response = httpclient.execute(httpget);
        HttpEntity entity = response.getEntity();
        int code = response.getStatusLine().getStatusCode();
        String reason = response.getStatusLine().getReasonPhrase();
        if (entity != null) {
            InputStream instream = entity.getContent();
            body = deserializeBody(instream);
            if (log.isDebugEnabled()) {
                log.debug("Http.getAsString url [" + url + "] response code [" + code + "] reason [" + reason
                        + "] body [" + body + "]");
            }
        } else {
            if (log.isDebugEnabled()) {
                log.debug("Http.getAsString url [" + url + "] response code [" + code + "] reason [" + reason
                        + "] body [nothing returned]");
            }
        }
    } catch (Exception e) {
        log.error("Http.getAsString failed, with url [" + url + "]", e);
    }
    return body;
}