Code example for HttpGet

Methods: addHeader

0
		this.initialized = true;
	} 
 
	// Set up the Getter with the API token and proper URL 
	private HttpGet getGetter(String targetURL) {
		HttpGet getter = new HttpGet(baseURL() + targetURL);	
		getter.addHeader("X-Spree-Token", this.apiKey);
		 
		return getter;
	} 
	 
	// Process the Getter and handle response exceptions 
	private HttpResponse getResponse(HttpGet getter) {
		if (getter == null)
			return null; 
		 
		try { 
			HttpResponse response = client.execute(getter);
			StatusLine statusLine = response.getStatusLine();
			int statusCode = statusLine.getStatusCode();
			if (statusCode == 200) {
				return response;
			} else { 
				Toast.makeText(ctx, getter.getURI() + "\nResponse not 200, Status: " + statusCode, Toast.LENGTH_LONG).show();
				Log.e("getHttpResponse", statusLine.toString());
			} 
		} catch (ClientProtocolException e) {
			Toast.makeText(ctx, "ClientProtocolException: " + e.getLocalizedMessage(), Toast.LENGTH_LONG).show();
		} catch (IOException e) {
			Toast.makeText(ctx, "IOException: " + e.getLocalizedMessage(), Toast.LENGTH_LONG).show();
		} 
 
		 
		// Something went wrong! 
		//Toast.makeText(ctx, "Server did not respond", Toast.LENGTH_LONG).show(); 
		return null; 
	} 
	 
	public String test() {
		int statusCode = 0;
		 
		HttpGet getter = getGetter("");
		 
		try { 
			HttpResponse response;
			response = client.execute(getter);
			StatusLine statusLine = response.getStatusLine();
			statusCode = statusLine.getStatusCode();
			response.getStatusLine();
			if (statusCode == 200) {
				return "OK";