Refine search
HttpClient client = new HttpClient(); // truststore KeyStore trustStore = KeyStore.getInstance("JKS", "SUN"); trustStore.load(TestSupertype.class.getResourceAsStream("/client-truststore.jks"), "amber%".toCharArray()); String alg = KeyManagerFactory.getDefaultAlgorithm(); TrustManagerFactory fac = TrustManagerFactory.getInstance(alg); fac.init(trustStore); // keystore KeyStore keystore = KeyStore.getInstance("PKCS12", "SunJSSE"); keystore.load(X509Test.class.getResourceAsStream("/etomcat_client.p12"), "etomcat".toCharArray()); String keyAlg = KeyManagerFactory.getDefaultAlgorithm(); KeyManagerFactory keyFac = KeyManagerFactory.getInstance(keyAlg); keyFac.init(keystore, "etomcat".toCharArray()); // context SSLContext ctx = SSLContext.getInstance("TLS", "SunJSSE"); ctx.init(keyFac.getKeyManagers(), fac.getTrustManagers(), new SecureRandom()); SslContextedSecureProtocolSocketFactory secureProtocolSocketFactory = new SslContextedSecureProtocolSocketFactory(ctx); Protocol.registerProtocol("https", new Protocol("https", (ProtocolSocketFactory) secureProtocolSocketFactory, 8443)); // test get HttpMethod get = new GetMethod("https://127.0.0.1:8443/etomcat_x509"); client.executeMethod(get); // get response body and do what you need with it byte[] responseBody = get.getResponseBody();
HttpClient client = new HttpClient(); int statusCode = client.executeMethod(method);
HttpClient client = new HttpClient(); int statusCode = client.executeMethod(method);
// Create an instance of HttpClient. HttpClient client = new HttpClient(); // Create a method instance. GetMethod method = new GetMethod(url); // Provide custom retry handler is necessary method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false)); try { // Execute the method. int statusCode = client.executeMethod(method); if (statusCode != HttpStatus.SC_OK) { System.err.println("Method failed: " + method.getStatusLine()); } // Read the response body. byte[] responseBody = method.getResponseBody(); // Deal with the response. // Use caution: ensure correct character encoding and is not binary data System.out.println(new String(responseBody)); } catch (HttpException e) { System.err.println("Fatal protocol violation: " + e.getMessage()); e.printStackTrace(); } catch (IOException e) { System.err.println("Fatal transport error: " + e.getMessage()); e.printStackTrace(); } finally { // Release the connection. method.releaseConnection(); }
HttpClient client = new HttpClient(); int statusCode = client.executeMethod(method);
PostMethod post = new PostMethod(url); RequestEntity entity = new FileRequestEntity(inputFile, "text/xml; charset=ISO-8859-1"); post.setRequestEntity(entity); HttpClient httpclient = new HttpClient(); int result = httpclient.executeMethod(post);
HttpClient client = new HttpClient(); HttpMethod method = new GetMethod("http://www.google.com"); int responseCode = client.executeMethod(method); if (responseCode != 200) { throw new HttpException("HttpMethod Returned Status Code: " + responseCode + " when attempting: " + url); } String rtn = StringEscapeUtils.unescapeHtml(method.getResponseBodyAsString());
Protocol easyhttps = new Protocol("https", (ProtocolSocketFactory)new EasySSLProtocolSocketFactory(), 443); Protocol.registerProtocol("https", easyhttps); HttpClient client = new HttpClient(); GetMethod httpget = new GetMethod("https://localhost/"); client.executeMethod(httpget);
HttpClient client = new HttpClient(); PostMethod method = new PostMethod(url); int statusCode = client.executeMethod(method);
HttpClient client = new HttpClient(); int statusCode = client.executeMethod(method);
System.setProperty("javax.net.ssl.keyStore", context.getRealPath(KEYSTORE)); System.setProperty("javax.net.ssl.keyStorePassword", "password"); System.setProperty("javax.net.ssl.trustStore", context.getRealPath(TRUSTSTORE)); System.setProperty("javax.net.debug", "ssl"); HttpClient httpClient = new HttpClient(); GetMethod httpGet = new GetMethod("https://something.com"); httpClient.executeMethod(httpGet); return new String(httpGet.getResponseBody());
try { String postURL= server; HttpClient client = new HttpClient(); PostMethod postMethod = new PostMethod(postURL);; client.executeMethod(postMethod); InputStream input = postMethod.getResponseBodyAsStream(); //--your subsequent code here
PostMethod post = new PostMethod("http://myservice.com"); // add the payload to the post object HttpClient client = new HttpClient(); int status = client.executeMethod(post); String response = post.getResponseBodyAsString();
// Create an instance of HttpClient. HttpClient client = new HttpClient(); // Create a method instance. GetMethod method = new GetMethod("http://localhost:9000/giveMeString"); // Execute the method. int statusCode = client.executeMethod(method); // Read the response body. byte[] responseBody = method.getResponseBody(); //Print the response System.out.println(new String(responseBody));
MultipartPostMethod method = new MultipartPostMethod( "http://localhost:8080/sendfile" ); method.addParameter("mediaFile", multifile ); HttpClient client1 = new HttpClient( ); // Execute and print response client1.executeMethod( method ); String response = method.getResponseBodyAsString( ); System.out.println( response ); method.releaseConnection( ); return response;
GetMethod get = new GetMethod("https://rest.nexmo.com/account/get-balance/{key}/{secret}"); HttpClient client = new HttpClient(); try { get.addRequestHeader("Accept", "application/xml"); //OR "application/json" int status = client.executeMethod(get); ...
PostMethod post = new PostMethod(url); // ... HttpClient httpclient = new HttpClient(); httpclient.getHttpConnectionManager().getConnection(HostConfiguration.ANY_HOST_CONFIGURATION); // ... httpclient.executeMethod(post);
String endPointFinal = endPoint.replaceAll("epaas://", "https://"); bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endPointFinal); bp.getRequestContext().put("SO_TIMEOUT", new Integer(sTimout)); bp.getRequestContext().put("CONNECTION_TIMEOUT", new Integer(cTimeout)); BrokeredEpaasSSLSocketFactory factory = new BrokeredEpaasSSLSocketFactory(); Protocol authhttps = new Protocol("https", factory, 443); HttpClient httpclient = new HttpClient(); URL URI = new URL(endPointFinal); httpclient.getHostConfiguration().setHost(URI.getHost(), 443, authhttps); GetMethod httpget = new GetMethod("/ecmuser/BrokeredConnectorService"); httpclient.executeMethod(httpget);
HttpClient client = new HttpClient(); client.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("test","test")); GetMethod getMethod = new GetMethod("http://www.example.com/mylogin"); client.executeMethod(getMethod); System.out.println(getMethod.getResponseBodyAsString());
final HttpClient client = new HttpClient(); client.getParams().setAuthenticationPreemptive(true); client.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(user.getUsername(), user.getPassword())); final GetMethod method = new GetMethod(uri); client.executeMethod(method);