Skip to content
This repository was archived by the owner on Oct 20, 2020. It is now read-only.

Latest commit

 

History

History
48 lines (38 loc) · 1 KB

async-get.md

File metadata and controls

48 lines (38 loc) · 1 KB

AsyncHttpClient Example GET

Example GET

	AsyncHttpClient client = new AsyncHttpClient("http://example.com");
	client.get("api/v1/", new JsonResponseHandler()
	{
		@Override public void onSuccess()
		{
			JsonElement result = getContent();
		}
	});

Example GET with parameters and headers

	AsyncHttpClient client = new AsyncHttpClient("http://example.com");

	List<NameValuePair> params = new ArrayList<>();
	params.add(new NameValuePair("key", "value"));

	Headers headers = Headers.of("Header", "value");

	client.get("api/v1/", params, headers, new JsonResponseHandler()
	{
		@Override public void onSuccess()
		{
			JsonElement result = getContent();
		}
	});

Example GET - Downloading a large file directly to cache

	AsyncHttpClient client = new AsyncHttpClient("http://example.com");

	client.get("api/v1/", new CacheResponseHandler("file.bin")
	{
		@Override public void onSuccess()
		{
			File result = getContent();
			boolean exists = result.exists();
		}
	});