Search in sources :

Example 41 with HttpGet

use of org.apache.http.client.methods.HttpGet in project qi4j-sdk by Qi4j.

the class MutualSecureJettyServiceTest method testWithoutClientCertificate.

@Test
public void testWithoutClientCertificate() throws IOException {
    // As we set wantClientAuth we can request without a client certificate ...
    String output = trustHttpClient.execute(new HttpGet("https://127.0.0.1:8441/hello"), stringResponseHandler);
    assertEquals("Hello World", output);
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) Test(org.junit.Test)

Example 42 with HttpGet

use of org.apache.http.client.methods.HttpGet in project Anki-Android by Ramblurr.

the class HttpFetcher method fetchThroughHttp.

public static String fetchThroughHttp(String address, String encoding) {
    try {
        HttpClient httpClient = new DefaultHttpClient();
        HttpContext localContext = new BasicHttpContext();
        HttpGet httpGet = new HttpGet(address);
        HttpResponse response = httpClient.execute(httpGet, localContext);
        if (!response.getStatusLine().toString().contains("OK")) {
            return "FAILED";
        }
        BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), Charset.forName(encoding)));
        StringBuilder stringBuilder = new StringBuilder();
        String line = null;
        while ((line = reader.readLine()) != null) {
            stringBuilder.append(line);
        }
        return stringBuilder.toString();
    } catch (Exception e) {
        return "FAILED with exception: " + e.getMessage();
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) BasicHttpContext(org.apache.http.protocol.BasicHttpContext) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) HttpGet(org.apache.http.client.methods.HttpGet) BasicHttpContext(org.apache.http.protocol.BasicHttpContext) HttpContext(org.apache.http.protocol.HttpContext) BufferedReader(java.io.BufferedReader) HttpResponse(org.apache.http.HttpResponse) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient)

Example 43 with HttpGet

use of org.apache.http.client.methods.HttpGet in project Notes by MiCode.

the class GTaskClient method getTaskLists.

public JSONArray getTaskLists() throws NetworkFailureException {
    if (!mLoggedin) {
        Log.e(TAG, "please login first");
        throw new ActionFailureException("not logged in");
    }
    try {
        HttpGet httpGet = new HttpGet(mGetUrl);
        HttpResponse response = null;
        response = mHttpClient.execute(httpGet);
        // get the task list
        String resString = getResponseContent(response.getEntity());
        String jsBegin = "_setup(";
        String jsEnd = ")}</script>";
        int begin = resString.indexOf(jsBegin);
        int end = resString.lastIndexOf(jsEnd);
        String jsString = null;
        if (begin != -1 && end != -1 && begin < end) {
            jsString = resString.substring(begin + jsBegin.length(), end);
        }
        JSONObject js = new JSONObject(jsString);
        return js.getJSONObject("t").getJSONArray(GTaskStringUtils.GTASK_JSON_LISTS);
    } catch (ClientProtocolException e) {
        Log.e(TAG, e.toString());
        e.printStackTrace();
        throw new NetworkFailureException("gettasklists: httpget failed");
    } catch (IOException e) {
        Log.e(TAG, e.toString());
        e.printStackTrace();
        throw new NetworkFailureException("gettasklists: httpget failed");
    } catch (JSONException e) {
        Log.e(TAG, e.toString());
        e.printStackTrace();
        throw new ActionFailureException("get task lists: handing jasonobject failed");
    }
}
Also used : ActionFailureException(net.micode.notes.gtask.exception.ActionFailureException) JSONObject(org.json.JSONObject) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) JSONException(org.json.JSONException) NetworkFailureException(net.micode.notes.gtask.exception.NetworkFailureException) IOException(java.io.IOException) ClientProtocolException(org.apache.http.client.ClientProtocolException)

Example 44 with HttpGet

use of org.apache.http.client.methods.HttpGet in project 9GAG by Mixiaoxiao.

the class MxxHttpUtil method doHttpGet.

public static String doHttpGet(String url, HashMap<String, String> map) {
    HttpClient client = new DefaultHttpClient();
    HttpConnectionParams.setConnectionTimeout(client.getParams(), TIMEOUT);
    HttpConnectionParams.setSoTimeout(client.getParams(), TIMEOUT);
    ConnManagerParams.setTimeout(client.getParams(), TIMEOUT);
    String result = "ERROR";
    if (null != map) {
        int i = 0;
        for (Map.Entry<String, String> entry : map.entrySet()) {
            if (i == 0) {
                url = url + "?" + entry.getKey() + "=" + entry.getValue();
            } else {
                url = url + "&" + entry.getKey() + "=" + entry.getValue();
            }
            i++;
        }
    }
    HttpGet get = new HttpGet(url);
    get.setHeaders(headers);
    try {
        HttpResponse response = client.execute(get);
        if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
            // setCookie(response);
            result = EntityUtils.toString(response.getEntity(), "UTF-8");
        } else {
            result = EntityUtils.toString(response.getEntity(), "UTF-8") + response.getStatusLine().getStatusCode() + "ERROR";
        }
        if (result != null) {
            if (result.startsWith("")) {
                result = result.substring(1);
            }
        }
    } catch (ConnectTimeoutException e) {
        result = "TIMEOUTERROR";
    } catch (Exception e) {
        result = "OTHERERROR";
        e.printStackTrace();
    }
    return result;
}
Also used : DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) HashMap(java.util.HashMap) Map(java.util.Map) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) ConnectTimeoutException(org.apache.http.conn.ConnectTimeoutException) IOException(java.io.IOException) ConnectTimeoutException(org.apache.http.conn.ConnectTimeoutException)

Example 45 with HttpGet

use of org.apache.http.client.methods.HttpGet in project nanohttpd by NanoHttpd.

the class GetAndPostIntegrationTest method testGetRequestWithParameters.

@Test
public void testGetRequestWithParameters() throws Exception {
    this.testServer.response = "testGetRequestWithParameters";
    HttpGet httpget = new HttpGet("http://localhost:8192/?age=120&gender=Male");
    ResponseHandler<String> responseHandler = new BasicResponseHandler();
    String responseBody = this.httpclient.execute(httpget, responseHandler);
    assertEquals("GET:testGetRequestWithParameters-params=2;age=120;gender=Male", responseBody);
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) BasicResponseHandler(org.apache.http.impl.client.BasicResponseHandler) Test(org.junit.Test)

Aggregations

HttpGet (org.apache.http.client.methods.HttpGet)1143 HttpResponse (org.apache.http.HttpResponse)717 Test (org.junit.Test)504 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)242 TestHttpClient (io.undertow.testutils.TestHttpClient)239 IOException (java.io.IOException)200 HttpClient (org.apache.http.client.HttpClient)185 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)179 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)176 HttpEntity (org.apache.http.HttpEntity)152 Header (org.apache.http.Header)133 InputStream (java.io.InputStream)103 URI (java.net.URI)83 JsonNode (com.fasterxml.jackson.databind.JsonNode)68 ArrayList (java.util.ArrayList)60 MockResponse (com.google.mockwebserver.MockResponse)54 HttpPost (org.apache.http.client.methods.HttpPost)54 Deployment (org.activiti.engine.test.Deployment)49 ClientProtocolException (org.apache.http.client.ClientProtocolException)46 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)45