$download = new HttpResponse(); $download->setFile('yourFile.ext'); $download->setBufferSize(20); $download->setThrottleDelay(.001); //set headers using either the corresponding methods: $download->setContentType('application/octet-stream'); //or the setHeader method $download->setHeader('Content-Length', filesize('yourFile.ext')); $download->send();
String id = "{\"ID\":\"John Doe\"}"; id = id.replace(":","%3A"); String encodedID = URLEncoder.encode(id, "UTF-8").replace("+", "%20"); endpoint="https://127.0.0.1/getResourceNameToUse?id=" + encodedID; HttpResponse response = new HttpResponse(); HttpGet httpget = new HttpGet(endpoint); response = httpclient.execute(httpget, new RESTResponseHandler());
Protocol.registerProtocol("vhttps", new Protocol("vhttps", new ValicertSSLProtocolSocketFactory(), 443)); PostMethod postMethod = new PostMethod(url); for (Map.Entry<String, String> entry : params.entrySet()) { postMethod.addParameter(entry.getKey(), StringUtils.Nz(entry.getValue())); } HttpClient client = new HttpClient(); int status = client.executeMethod(postMethod); if (status == 200) { StringBuilder resultBuffer = new StringBuilder(); resultBuffer.append(postMethod.getResponseBodyAsString()); return new HttpResponse(resultBuffer.toString(), ""); } else { throw new IOException("Invalid response code: " + status); }
Protocol.registerProtocol("vhttps", new Protocol("vhttps", new ValicertSSLProtocolSocketFactory(), 443)); PostMethod postMethod = new PostMethod(url); for (Map.Entry<String, String> entry : params.entrySet()) { postMethod.addParameter(entry.getKey(), StringUtils.Nz(entry.getValue())); } HttpClient client = new HttpClient(); int status = client.executeMethod(postMethod); if (status == 200) { StringBuilder resultBuffer = new StringBuilder(); resultBuffer.append(postMethod.getResponseBodyAsString()); return new HttpResponse(resultBuffer.toString(), ""); } else { throw new IOException("Invalid response code: " + status); }