HttpClient httpClient = new HttpClient(); httpClient.getHostConfiguration().setProxy("localhost", 8888);
Protocol authhttps = new Protocol("https", new AuthSSLProtocolSocketFactory( new URL("file:my.keystore"), "mypassword", new URL("file:my.truststore"), "mypassword"), 443); HttpClient client = new HttpClient(); client.getHostConfiguration().setHost("localhost", 443, authhttps);
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 httpclient = new HttpClient(); if (System.getProperty("http.proxyHost") != null) { try { HostConfiguration hostConfiguration = httpclient.getHostConfiguration(); hostConfiguration.setProxy(System.getProperty("http.proxyHost"), Integer.parseInt(System.getProperty("http.proxyPort"))); httpclient.setHostConfiguration(hostConfiguration); this.getLogger().warn("USING PROXY: "+httpclient.getHostConfiguration().getProxyHost()); } catch (Exception e) { throw new ProcessingException("Cannot set proxy!", e); } }
HttpClient client = new HttpClient(); HttpMethod method = new GetMethod("http://www.kodejava.org"); HostConfiguration config = client.getHostConfiguration(); config.setProxy(PROXY_HOST, PROXY_PORT); String username = "guest"; String password = "s3cr3t"; Credentials credentials = new UsernamePasswordCredentials(username, password); AuthScope authScope = new AuthScope(PROXY_HOST, PROXY_PORT); client.getState().setProxyCredentials(authScope, credentials);
String url = "https://login.yahoo.com"; String _strGetRspBody; String _strPostRspBody; int port = 443; HttpClient httpClient = new HttpClient(new MultiThreadedHttpConnectionManager()); httpClient.getHostConfiguration().setHost(url, port, "https"); GetMethod authget = new GetMethod(url); try { httpClient.executeMethod(authget); } catch (IOException i) { logger.error(i.toString()); } InputStream d = authget.getResponseBodyAsStream();
class Proxy extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { // Perform a new request to get contents from secured page HttpClient client = new HttpClient(); Credentials credentials = new UsernamePasswordCredentials("user", "pass"); client.getState().setCredentials(authScope, credentials); GetMethod method = new GetMethod("/secure_page.jsp"); client.executeMethod(client.getHostConfiguration();, method); // write result to the outputstream resp.getWriter().write( method.getResponseBodyAsString() ); } }
HttpClient httpclient = new HttpClient(); httpclient.getHostConfiguration().setProxy("myproxyhost", 8080); httpclient.getState().setProxyCredentials("my-proxy-realm", " myproxyhost", new UsernamePasswordCredentials("my-proxy-username", "my-proxy-password")); GetMethod httpget = new GetMethod("https://www.verisign.com/"); try { httpclient.executeMethod(httpget); System.out.println(httpget.getStatusLine()); } finally { httpget.releaseConnection(); }
HttpClient httpclient = new HttpClient(); httpclient.getHostConfiguration().setProxy("myproxyhost", 8080); httpclient.getState().setProxyCredentials("my-proxy-realm", " myproxyhost", new UsernamePasswordCredentials("my-proxy-username", "my-proxy-password")); GetMethod httpget = new GetMethod("https://www.verisign.com/"); try { httpclient.executeMethod(httpget); System.out.println(httpget.getStatusLine()); } finally { httpget.releaseConnection(); }
HttpClient client = new HttpClient(); client.getHostConfiguration().setProxy("companyproxy.server", 8080); List authPrefs = new ArrayList(); authPrefs.add(AuthPolicy.NTLM); client.getState().setProxyCredentials( new AuthScope(null, 8080, null), new NTCredentials("username", "pwd", "", "DOMAIN")); client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); GetMethod method = new GetMethod(url); method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false));
String server = "example.com"; int port = 443; EasySSLProtocolSocketFactory psf = new EasySSLProtocolSocketFactory(); InputStream is = readFile("/path/to/certificate"); KeyMaterial km = new KeyMaterial(is, "certpasswd".toCharArray()); easy.setKeyMaterial(km); Protocol proto = new Protocol("https", (ProtocolSocketFactory) psf, port); HttpClient httpclient = new HttpClient(); httpclient.getHostConfiguration().setHost(server, port, proto);
HttpClient client = new HttpClient(); HostConfiguration hostConfiguration = client.getHostConfiguration(); hostConfiguration.setProxy("localhost", 8080); client.setHostConfiguration(hostConfiguration);
AuthScope auth=new AuthScope(testAuthData.getHost(),Integer.parseInt(testAuthData.getPort())); ReportData report=new ReportData(); report.setEndPoint(input.getEndPoint()); report.setRequest(xml); Credentials defaultProxyCreds = new UsernamePasswordCredentials( testAuthData.getUsername(), testAuthData.getPassword()); HttpClient httpClient = new HttpClient(); httpClient.getHostConfiguration().setProxy(testAuthData.getHost(),Integer.parseInt(testAuthData.getPort())); httpClient.getState().setProxyCredentials(auth, defaultProxyCreds); PostMethod post = new PostMethod(input.getEndPoint()); post.addRequestHeader("header1", "header1Value"); post.setRequestEntity(new StringRequestEntity(xml, "application/xml", null)); int responseCode = httpClient.executeMethod(post); //httpClient.ex byte[] resp=post.getResponseBody(); String s = new String(resp); System.out.println("response:"+s); report.setResponse(s); System.out.println("responseCode:"+responseCode); Header header= post.getResponseHeader("header1");
client.getHostConfiguration().setHost(getHostName(), getPort(), protocol); method = new GetMethod(getContextPath()); method.setFollowRedirects(true);
HttpClient httpclient = new HttpClient(); httpclient.getHostConfiguration().setProxy("myproxyhost", 8080); /* Optional if authentication is required. httpclient.getState().setProxyCredentials("my-proxy-realm", " myproxyhost", new UsernamePasswordCredentials("my-proxy-username", "my-proxy-password")); */ PostMethod post = new PostMethod("https://someurl"); NameValuePair[] data = { new NameValuePair("user", "joe"), new NameValuePair("password", "bloggs") }; post.setRequestBody(data); // execute method and handle any error responses. // ... InputStream in = post.getResponseBodyAsStream(); // handle response. /* Example for a GET reqeust GetMethod httpget = new GetMethod("https://someurl"); try { httpclient.executeMethod(httpget); System.out.println(httpget.getStatusLine()); } finally { httpget.releaseConnection(); } */