public static HttpUriRequest constructRequest(String host, Endpoint endpoint, Authentication auth) { String url = host + endpoint.getURI(); if (endpoint.getHttpMethod().equalsIgnoreCase(HttpGet.METHOD_NAME)) { HttpGet get = new HttpGet(url); if (auth != null) auth.signRequest(get, null); return get; } else if (endpoint.getHttpMethod().equalsIgnoreCase(HttpPost.METHOD_NAME) ) { HttpPost post = new HttpPost(url); post.setEntity(new StringEntity(endpoint.getPostParamString(), Constants.DEFAULT_CHARSET)); post.setHeader(HttpHeaders.CONTENT_TYPE, "application/x-www-form-urlencoded"); if (auth != null) auth.signRequest(post, endpoint.getPostParamString()); return post; } else { throw new IllegalArgumentException("Bad http method: " + endpoint.getHttpMethod()); } } }