Search in sources :

Example 1 with HttpResponse

use of org.pixmob.httpclient.HttpResponse in project httpclient by pixmob.

the class PostFormTask method doRun.

@Override
protected void doRun() throws Exception {
    final HttpClient hc = createClient();
    hc.post("http://groovyconsole.appspot.com/executor.groovy").param("script", "printf 'Hello Android!'").to(new HttpResponseHandler() {

        @Override
        public void onResponse(HttpResponse response) throws Exception {
            final StringBuilder rawJson = new StringBuilder(64);
            response.read(rawJson);
            final JSONObject json = new JSONObject(rawJson.toString());
            assertEquals("Hello Android!", json.getString("outputText"));
        }
    }).execute();
    final HttpResponse resp = hc.post("http://groovyconsole.appspot.com/executor.groovy").param("script", "printf 'Hello Android! (inline)'").execute();
    final StringBuilder rawJson = new StringBuilder(64);
    resp.read(rawJson);
    final JSONObject json = new JSONObject(rawJson.toString());
    assertEquals("Hello Android! (inline)", json.getString("outputText"));
}
Also used : JSONObject(org.json.JSONObject) HttpClient(org.pixmob.httpclient.HttpClient) HttpResponse(org.pixmob.httpclient.HttpResponse) HttpResponseHandler(org.pixmob.httpclient.HttpResponseHandler)

Example 2 with HttpResponse

use of org.pixmob.httpclient.HttpResponse in project httpclient by pixmob.

the class RedirectTask method doRun.

@Override
protected void doRun() throws Exception {
    final HttpClient hc = createClient();
    final HttpResponse response = hc.get("http://google.com").expect(HttpURLConnection.HTTP_MOVED_PERM).execute();
    assertEquals("text/html", response.getContentType());
    assertEquals("UTF-8", response.getContentCharset());
}
Also used : HttpClient(org.pixmob.httpclient.HttpClient) HttpResponse(org.pixmob.httpclient.HttpResponse)

Aggregations

HttpClient (org.pixmob.httpclient.HttpClient)2 HttpResponse (org.pixmob.httpclient.HttpResponse)2 JSONObject (org.json.JSONObject)1 HttpResponseHandler (org.pixmob.httpclient.HttpResponseHandler)1