HttpResponse response = httpClient.execute(new HttpGet(URL)); String responseString = new BasicResponseHandler().handleResponse(response); System.out.println(responseString);
public static HttpResponse makeRequest(String path, Map params) throws Exception { //instantiates httpclient to make request DefaultHttpClient httpclient = new DefaultHttpClient(); //url with the post data HttpPost httpost = new HttpPost(path); //convert parameters into JSON object JSONObject holder = getJsonObjectFromMap(params); //passes the results to a string builder/entity StringEntity se = new StringEntity(holder.toString()); //sets the post request as the resulting string httpost.setEntity(se); //sets a request header so the page receving the request //will know what to do with it httpost.setHeader("Accept", "application/json"); httpost.setHeader("Content-type", "application/json"); //Handles what is returned from the page ResponseHandler responseHandler = new BasicResponseHandler(); return httpclient.execute(httpost, responseHandler); }
@Test public void shouldSupportBasicResponseHandlerHandleResponse() throws Exception { FakeHttp.addPendingHttpResponse(200, "OK", new BasicHeader("Content-Type", "text/plain")); DefaultHttpClient client = new DefaultHttpClient(); HttpResponse response = client.execute(new HttpGet("http://www.nowhere.org")); assertThat(((HttpUriRequest) FakeHttp.getSentHttpRequest(0)).getURI()) .isEqualTo(URI.create("http://www.nowhere.org")); Assert.assertNotNull(response); String responseStr = new BasicResponseHandler().handleResponse(response); Assert.assertEquals("OK", responseStr); }
String resultContent = new BasicResponseHandler().handleResponse(response); WxError error = WxError.fromJson(resultContent); if (error.getErrorCode() != 0) {
String resultContent = null; try (CloseableHttpResponse response = httpclient.execute(httpGet)) { resultContent = new BasicResponseHandler().handleResponse(response);
HttpGet request = new HttpGet(URL + q); request.addHeader("deviceId", deviceId); ResponseHandler<string> handler = new BasicResponseHandler(); try { result = httpclient.execute(request, handler);
private String executeMethod(HttpRequestBase req, String path) { try { URI base = new URI(apiUrl); req.setURI(new URI(base.getScheme(), base.getUserInfo(), base.getHost(), base.getPort(), path, null, null)); } catch (URISyntaxException e) { s_logger.error("invalid API URL " + apiUrl + " path " + path, e); return null; } try { String content = null; try { content = getHttpClient().execute(req, new BasicResponseHandler()); s_logger.info("ssp api call: " + req); } catch (HttpResponseException e) { s_logger.info("ssp api call failed: " + req, e); if (e.getStatusCode() == HttpStatus.SC_UNAUTHORIZED && login()) { req.reset(); content = getHttpClient().execute(req, new BasicResponseHandler()); s_logger.info("ssp api retry call: " + req); } } return content; } catch (ClientProtocolException e) { // includes HttpResponseException s_logger.error("ssp api call failed: " + req, e); } catch (IOException e) { s_logger.error("ssp api call failed: " + req, e); } return null; }
ResponseHandler<String> responseHandler = new BasicResponseHandler(); try { responseBody = s_httpclient.execute(get_request, responseHandler); throw new ExecutionException(e.getMessage()); ResponseHandler<String> responseHandler = new BasicResponseHandler(); try { responseBody = s_httpclient.execute(post_request, responseHandler);
return new DefaultHttpClient().execute(new HttpGet(getUrl()), new BasicResponseHandler());
synchronized private void doRegister(String service) { String url = registryURL; try { HttpPut method = new HttpPut(url); method.addHeader("service", service); ResponseHandler<String> handler = new BasicResponseHandler(); String responseBody = httpClient.execute(method, handler); LOG.debug("PUT to " + url + " got a " + responseBody); } catch (Exception e) { LOG.debug("PUT to " + url + " failed with: " + e); } }
Thread t = new Thread() { public void run() { //sending data to server response = httpClient.execute(httppost, new BasicResponseHandler()).trim(); } }; t.start(); t.join();
protected void dismissHelpTip(String tipId) throws Exception { HttpPost request = new HttpPost(baseUrl + "/rest/helptips/1.0/tips"); request.setEntity(new StringEntity(new JSONObject(ImmutableMap.<String, Object>of("id", tipId)).toString(), ContentType.APPLICATION_JSON)); userRequestSender.sendRequestAsUser(request, new BasicResponseHandler(), defaultUsername, defaultPassword); } }
@Override Reader getCheckDefinitions(String location) throws IOException { HttpClient httpClient = new DefaultHttpClient(); HttpGet get = new HttpGet(getName() + COLON + DOUBLE_SLASH + location); String response = httpClient.execute(get, new BasicResponseHandler()); return new StringReader(response); }
@Override public ModifyCallResponse parseResponse(HttpResponse response) throws IOException { String json = new BasicResponseHandler().handleResponse(response); if (response.getStatusLine().getStatusCode() == 200) { return ModifyCallResponse.fromJson(json); } else { return null; } }
public String getUpmPluginJson(String appKey) throws Exception { HttpGet get = new HttpGet(UpmTokenRequestor.getUpmPluginResource(baseUrl, appKey)); ResponseHandler<String> responseHandler = new BasicResponseHandler(); return userRequestSender.sendRequestAsUser(get, responseHandler, defaultUsername, defaultPassword); }
public void uninstallSystemAddon(String addonKey) throws Exception { HttpDelete delete = new HttpDelete(baseUrl + "/rest/remoteplugintest/1/addon-control/" + addonKey); ResponseHandler<String> responseHandler = new BasicResponseHandler(); try { userRequestSender.sendRequestAsUser(delete, responseHandler, defaultUsername, defaultPassword); } catch (HttpResponseException e) { //eat 404's as it means the addon does not exist if (e.getStatusCode() != 404) { throw e; } } }
public String getUpmPluginJson(String appKey) throws Exception { HttpGet get = new HttpGet(UpmTokenRequestor.getUpmPluginResource(baseUrl, appKey)); ResponseHandler<String> responseHandler = new BasicResponseHandler(); return userRequestSender.sendRequestAsUser(get, responseHandler, defaultUsername, defaultPassword); }
@Override public DtmfResponse parseResponse(HttpResponse response) throws IOException { String json = new BasicResponseHandler().handleResponse(response); return DtmfResponse.fromJson(json); }
public void uninstall(String appKey) throws Exception { HttpDelete delete = new HttpDelete(UpmTokenRequestor.getUpmPluginResource(baseUrl, appKey)); ResponseHandler<String> responseHandler = new BasicResponseHandler(); try { userRequestSender.sendRequestAsUser(delete, responseHandler, defaultUsername, defaultPassword); } catch (HttpResponseException e) { //eat 404's as it means the addon does not exist if (e.getStatusCode() != 404) { throw e; } } }