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();
}
}
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);
}
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);
}
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());
}
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());
}
Aggregations