Search in sources :

Example 1 with BasicResponseHandler

use of org.apache.http.impl.client.BasicResponseHandler in project cw-android by commonsguy.

the class WeatherDemo method updateForecast.

private void updateForecast(Location loc) {
    String url = String.format(format, loc.getLatitude(), loc.getLongitude());
    HttpGet getMethod = new HttpGet(url);
    try {
        ResponseHandler<String> responseHandler = new BasicResponseHandler();
        String responseBody = client.execute(getMethod, responseHandler);
        buildForecasts(responseBody);
        String page = generatePage();
        browser.loadDataWithBaseURL(null, page, "text/html", "UTF-8", null);
    } catch (Throwable t) {
        android.util.Log.e("WeatherDemo", "Exception fetching data", t);
        Toast.makeText(this, "Request failed: " + t.toString(), Toast.LENGTH_LONG).show();
    }
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) BasicResponseHandler(org.apache.http.impl.client.BasicResponseHandler)

Example 2 with BasicResponseHandler

use of org.apache.http.impl.client.BasicResponseHandler 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)

Example 3 with BasicResponseHandler

use of org.apache.http.impl.client.BasicResponseHandler in project nanohttpd by NanoHttpd.

the class PutStreamIntegrationTest method testSimplePutRequest.

@Test
public void testSimplePutRequest() throws Exception {
    String expected = "This HttpPut request has a content-length of 48.";
    HttpPut httpput = new HttpPut("http://localhost:8192/");
    httpput.setEntity(new ByteArrayEntity(expected.getBytes()));
    ResponseHandler<String> responseHandler = new BasicResponseHandler();
    String responseBody = this.httpclient.execute(httpput, responseHandler);
    assertEquals("PUT:" + expected, responseBody);
}
Also used : ByteArrayEntity(org.apache.http.entity.ByteArrayEntity) BasicResponseHandler(org.apache.http.impl.client.BasicResponseHandler) HttpPut(org.apache.http.client.methods.HttpPut) Test(org.junit.Test)

Example 4 with BasicResponseHandler

use of org.apache.http.impl.client.BasicResponseHandler in project nanohttpd by NanoHttpd.

the class CookieIntegrationTest method testMultipleCookieSentBackToClient.

@Test
public void testMultipleCookieSentBackToClient() throws Exception {
    this.testServer.cookiesToSend.add(new Cookie("name0", "value0", 30));
    this.testServer.cookiesToSend.add(new Cookie("name1", "value1", 30));
    this.testServer.cookiesToSend.add(new Cookie("name2", "value2", 30));
    this.testServer.cookiesToSend.add(new Cookie("name3", "value3", 30));
    HttpGet httpget = new HttpGet("http://localhost:8192/");
    ResponseHandler<String> responseHandler = new BasicResponseHandler();
    this.httpclient.execute(httpget, responseHandler);
    assertEquals(4, this.httpclient.getCookieStore().getCookies().size());
}
Also used : BasicClientCookie(org.apache.http.impl.cookie.BasicClientCookie) Cookie(org.nanohttpd.protocols.http.content.Cookie) HttpGet(org.apache.http.client.methods.HttpGet) BasicResponseHandler(org.apache.http.impl.client.BasicResponseHandler) Test(org.junit.Test)

Example 5 with BasicResponseHandler

use of org.apache.http.impl.client.BasicResponseHandler in project nanohttpd by NanoHttpd.

the class CookieIntegrationTest method testServerReceivesMultipleCookiesSentFromClient.

@Test
public void testServerReceivesMultipleCookiesSentFromClient() throws Exception {
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.DAY_OF_YEAR, 100);
    Date date = calendar.getTime();
    BasicClientCookie clientCookie0 = new BasicClientCookie("name0", "value0");
    BasicClientCookie clientCookie1 = new BasicClientCookie("name1", "value1");
    BasicClientCookie clientCookie2 = new BasicClientCookie("name2", "value2");
    BasicClientCookie clientCookie3 = new BasicClientCookie("name3", "value3");
    clientCookie0.setExpiryDate(date);
    clientCookie0.setDomain("localhost");
    clientCookie1.setExpiryDate(date);
    clientCookie1.setDomain("localhost");
    clientCookie2.setExpiryDate(date);
    clientCookie2.setDomain("localhost");
    clientCookie3.setExpiryDate(date);
    clientCookie3.setDomain("localhost");
    this.httpclient.getCookieStore().addCookie(clientCookie0);
    this.httpclient.getCookieStore().addCookie(clientCookie1);
    this.httpclient.getCookieStore().addCookie(clientCookie2);
    this.httpclient.getCookieStore().addCookie(clientCookie3);
    HttpGet httpget = new HttpGet("http://localhost:8192/");
    ResponseHandler<String> responseHandler = new BasicResponseHandler();
    this.httpclient.execute(httpget, responseHandler);
    assertEquals(4, this.testServer.cookiesReceived.size());
}
Also used : Calendar(java.util.Calendar) HttpGet(org.apache.http.client.methods.HttpGet) BasicResponseHandler(org.apache.http.impl.client.BasicResponseHandler) BasicClientCookie(org.apache.http.impl.cookie.BasicClientCookie) Date(java.util.Date) Test(org.junit.Test)

Aggregations

BasicResponseHandler (org.apache.http.impl.client.BasicResponseHandler)39 HttpGet (org.apache.http.client.methods.HttpGet)26 Test (org.junit.Test)15 IOException (java.io.IOException)10 HttpPost (org.apache.http.client.methods.HttpPost)10 ArrayList (java.util.ArrayList)7 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)7 NameValuePair (org.apache.http.NameValuePair)6 HttpClient (org.apache.http.client.HttpClient)6 HttpResponseException (org.apache.http.client.HttpResponseException)6 UrlEncodedFormEntity (org.apache.http.client.entity.UrlEncodedFormEntity)6 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)6 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)6 ClientProtocolException (org.apache.http.client.ClientProtocolException)5 RequestConfig (org.apache.http.client.config.RequestConfig)5 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)4 BasicClientCookie (org.apache.http.impl.cookie.BasicClientCookie)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2