use of org.pixmob.httpclient.HttpClient in project httpclient by pixmob.
the class ContentTypeTask method doRun.
@Override
protected void doRun() throws Exception {
final HttpClient hc = createClient();
hc.get("http://www.wired.com/").to(new CheckContentHandler("text/html", "UTF-8")).execute();
hc.head("http://www.google.com/intl/en_com/images/srpr/logo3w.png").to(new CheckContentHandler("image/png", null)).execute();
}
use of org.pixmob.httpclient.HttpClient in project httpclient by pixmob.
the class DownloadFileTask method doRun.
@Override
protected void doRun() throws Exception {
final File imgFile = new File(getContext().getCacheDir(), "google_logo.png");
imgFile.delete();
final HttpClient hc = createClient();
hc.get("http://www.google.fr/images/srpr/logo3w.png").to(imgFile).execute();
if (!imgFile.exists() || imgFile.length() == 0) {
throw new TaskExecutionFailedException("File download failed");
}
}
use of org.pixmob.httpclient.HttpClient in project httpclient by pixmob.
the class GoogleAppEngineAuthTask method doRun.
@Override
protected void doRun() throws Exception {
final AccountManager am = (AccountManager) getContext().getSystemService(Context.ACCOUNT_SERVICE);
final Account[] accounts = am.getAccountsByType(GoogleAppEngineAuthenticator.GOOGLE_ACCOUNT_TYPE);
if (accounts == null || accounts.length == 0) {
throw new IllegalStateException("No Google account found");
}
final String gaeHost = "pushpushandroid.appspot.com";
final GoogleAppEngineAuthenticator auth = new GoogleAppEngineAuthenticator(getContext(), accounts[0], gaeHost);
final HttpClient hc = createClient();
hc.head("https://" + gaeHost).with(auth).execute();
}
use of org.pixmob.httpclient.HttpClient 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"));
}
use of org.pixmob.httpclient.HttpClient 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());
}
Aggregations