List of usage examples for org.apache.http.conn.params ConnRoutePNames DEFAULT_PROXY
String DEFAULT_PROXY
To view the source code for org.apache.http.conn.params ConnRoutePNames DEFAULT_PROXY.
Click Source Link
From source file:com.reversemind.glia.test.go3.java
public static void main(String... args) throws Exception { System.setProperty("http.proxyHost", "10.105.0.217"); System.setProperty("http.proxyPort", "3128"); System.setProperty("https.proxyHost", "10.105.0.217"); System.setProperty("https.proxyPort", "3128"); HttpHost proxy = new HttpHost("10.105.0.217", 3128); DefaultHttpClient client = new DefaultHttpClient(); client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); HttpGet request = new HttpGet( "https://twitter.com/i/profiles/show/splix/timeline/with_replies?include_available_features=1&include_entities=1&max_id=285605679744569344"); HttpResponse response = client.execute(request); // Get the response BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8")); String sl = ""; String line = ""; while ((line = rd.readLine()) != null) { LOG.debug(line);//from w ww . j a v a 2 s. c om sl += line; } sl = new String(sl.getBytes(), "UTF-8"); String sss = sl.replaceAll("\\{1,}", "\\").replaceAll("\\\"", "'").replaceAll("\\"", "'") .replaceAll(">", ">").replaceAll("<", "<").replaceAll("&", "&").replaceAll("'", "'") .replaceAll("\u003c", "<").replaceAll("\u003e", ">").replaceAll("\n", " ").replaceAll("\\/", "/") .replaceAll("\\'", "'"); String sss2 = sss.replaceAll("\\'", "'"); LOG.debug(sss); save("/opt/_del/go_sl.txt", sl); save("/opt/_del/go_sss.txt", sss); save("/opt/_del/go_line.txt", line); save("/opt/_del/go_sss2.txt", sss2); LOG.debug("\n\n\n\n\n"); LOG.debug(sss); LOG.debug("\n\n\n\n\n"); LOG.debug(URLDecoder.decode(sl, "UTF-8")); LOG.debug(URLDecoder.decode("\u0438\u043d\u043e\u0433\u0434\u0430", "UTF-8")); LOG.debug(URLDecoder.decode("\n \u003c/span\u003e\n \u003cb\u003e\n ", "UTF-8")); }
From source file:com.hsbc.frc.SevenHero.ClientExecuteProxy.java
public static void main(String[] args) throws Exception { HttpHost proxy = new HttpHost("133.13.162.149", 8080, "http"); DefaultHttpClient httpclient = new DefaultHttpClient(); try {// w w w . j a v a 2s . co m httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); HttpHost target = new HttpHost("pt.3g.qq.com"); HttpGet req = new HttpGet("/"); System.out.println("executing request to " + target + " via " + proxy); HttpResponse rsp = httpclient.execute(target, req); HttpEntity entity = rsp.getEntity(); System.out.println("----------------------------------------"); System.out.println(rsp.getStatusLine()); Header[] headers = rsp.getAllHeaders(); for (int i = 0; i < headers.length; i++) { System.out.println(headers[i]); } System.out.println("----------------------------------------"); if (entity != null) { System.out.println(EntityUtils.toString(entity)); } } finally { // When HttpClient instance is no longer needed, // shut down the connection manager to ensure // immediate deallocation of all system resources httpclient.getConnectionManager().shutdown(); } }
From source file:com.dlmu.heipacker.crawler.client.ClientExecuteProxy.java
public static void main(String[] args) throws Exception { HttpHost proxy = new HttpHost("127.0.0.1", 8080, "http"); DefaultHttpClient httpclient = new DefaultHttpClient(); try {/*from ww w . ja va 2s. c o m*/ httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); HttpHost target = new HttpHost("issues.apache.org", 443, "https"); HttpGet req = new HttpGet("/"); System.out.println("executing request to " + target + " via " + proxy); HttpResponse rsp = httpclient.execute(target, req); HttpEntity entity = rsp.getEntity(); System.out.println("----------------------------------------"); System.out.println(rsp.getStatusLine()); Header[] headers = rsp.getAllHeaders(); for (int i = 0; i < headers.length; i++) { System.out.println(headers[i]); } System.out.println("----------------------------------------"); if (entity != null) { System.out.println(EntityUtils.toString(entity)); } } finally { // When HttpClient instance is no longer needed, // shut down the connection manager to ensure // immediate deallocation of all system resources httpclient.getConnectionManager().shutdown(); } }
From source file:com.mtea.macrotea_httpclient_study.ClientExecuteProxy.java
public static void main(String[] args) throws Exception { //?//from w ww . ja v a 2 s.co m HttpHost proxy = new HttpHost("127.0.0.1", 8080, "http"); DefaultHttpClient httpclient = new DefaultHttpClient(); try { //httpclient??? httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); //? HttpHost target = new HttpHost("issues.apache.org", 443, "https"); HttpGet req = new HttpGet("/"); System.out.println("executing request to " + target + " via " + proxy); HttpResponse rsp = httpclient.execute(target, req); HttpEntity entity = rsp.getEntity(); System.out.println("----------------------------------------"); System.out.println(rsp.getStatusLine()); //??? Header[] headers = rsp.getAllHeaders(); for (int i = 0; i < headers.length; i++) { System.out.println(headers[i]); } System.out.println("----------------------------------------"); if (entity != null) { System.out.println(EntityUtils.toString(entity)); } } finally { //??httpclient??? httpclient.getConnectionManager().shutdown(); } }
From source file:test.ClientTest.java
public static void main(String[] args) throws Exception { DefaultHttpClient httpclient = new DefaultHttpClient(); HttpHost proxy = new HttpHost("192.168.1.158", 8080, "http"); // httpclient.getCredentialsProvider().setCredentials(new AuthScope("192.168.1.158", 8080),new UsernamePasswordCredentials("", "")); try {// w w w . j av a2 s . c o m httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); HttpHost target = new HttpHost("www.drugoogle.com", 80, "http"); HttpGet httpget = new HttpGet("/index/index.htm"); System.out.println("executing request to " + httpget); HttpResponse rsp = httpclient.execute(target, httpget); HttpEntity entity = rsp.getEntity(); System.out.println("----------------------------------------"); System.out.println(rsp.getStatusLine()); Header[] headers = rsp.getAllHeaders(); for (int i = 0; i < headers.length; i++) { System.out.println(headers[i]); } System.out.println("----------------------------------------"); if (entity != null) { System.out.println(EntityUtils.toString(entity, "UTF-8")); } } finally { // When HttpClient instance is no longer needed, // shut down the connection manager to ensure // immediate deallocation of all system resources httpclient.getConnectionManager().shutdown(); } }
From source file:httpclient.client.ClientProxyAuthentication.java
public static void main(String[] args) throws Exception { DefaultHttpClient httpclient = new DefaultHttpClient(); httpclient.getCredentialsProvider().setCredentials(new AuthScope("localhost", 8080), new UsernamePasswordCredentials("username", "password")); HttpHost targetHost = new HttpHost("www.verisign.com", 443, "https"); HttpHost proxy = new HttpHost("localhost", 8080); httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); HttpGet httpget = new HttpGet("/"); System.out.println("executing request: " + httpget.getRequestLine()); System.out.println("via proxy: " + proxy); System.out.println("to target: " + targetHost); HttpResponse response = httpclient.execute(targetHost, httpget); HttpEntity entity = response.getEntity(); System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); if (entity != null) { System.out.println("Response content length: " + entity.getContentLength()); }/*from w w w.j a v a 2 s . co m*/ if (entity != null) { entity.consumeContent(); } // When HttpClient instance is no longer needed, // shut down the connection manager to ensure // immediate deallocation of all system resources httpclient.getConnectionManager().shutdown(); }
From source file:com.dlmu.heipacker.crawler.client.ClientProxyAuthentication.java
public static void main(String[] args) throws Exception { DefaultHttpClient httpclient = new DefaultHttpClient(); try {//from w ww .j a v a2 s.c o m httpclient.getCredentialsProvider().setCredentials(new AuthScope("localhost", 8080), new UsernamePasswordCredentials("username", "password")); HttpHost targetHost = new HttpHost("www.verisign.com", 443, "https"); HttpHost proxy = new HttpHost("localhost", 8080); httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); HttpGet httpget = new HttpGet("/"); System.out.println("executing request: " + httpget.getRequestLine()); System.out.println("via proxy: " + proxy); System.out.println("to target: " + targetHost); HttpResponse response = httpclient.execute(targetHost, httpget); HttpEntity entity = response.getEntity(); System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); if (entity != null) { System.out.println("Response content length: " + entity.getContentLength()); } EntityUtils.consume(entity); } finally { // When HttpClient instance is no longer needed, // shut down the connection manager to ensure // immediate deallocation of all system resources httpclient.getConnectionManager().shutdown(); } }
From source file:com.hsbc.frc.SevenHero.ClientPreemptiveBasicAuthentication.java
public static void main(String[] args) throws Exception { HttpHost proxy = new HttpHost("133.13.162.149", 8080, "http"); HttpHost targetHost = new HttpHost("pt.3g.qq.com"); DefaultHttpClient httpclient = new DefaultHttpClient(); try {// ww w . ja va 2 s. co m httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); httpclient.getCredentialsProvider().setCredentials( new AuthScope(targetHost.getHostName(), targetHost.getPort()), new UsernamePasswordCredentials("username", "password")); // Create AuthCache instance AuthCache authCache = new BasicAuthCache(); // Generate BASIC scheme object and add it to the local // auth cache BasicScheme basicAuth = new BasicScheme(); authCache.put(targetHost, basicAuth); // Add AuthCache to the execution context BasicHttpContext localcontext = new BasicHttpContext(); localcontext.setAttribute(ClientContext.AUTH_CACHE, authCache); HttpGet httpget = new HttpGet("/"); System.out.println("executing request: " + httpget.getRequestLine()); System.out.println("to target: " + targetHost); for (int i = 0; i < 3; i++) { HttpResponse response = httpclient.execute(targetHost, httpget, localcontext); HttpEntity entity = response.getEntity(); System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); if (entity != null) { System.out.println("Response content length: " + entity.getContentLength()); } EntityUtils.consume(entity); } } finally { // When HttpClient instance is no longer needed, // shut down the connection manager to ensure // immediate deallocation of all system resources httpclient.getConnectionManager().shutdown(); } }
From source file:com.hsbc.frc.SevenHero.ClientProxyAuthentication.java
public static void main(String[] args) throws Exception { DefaultHttpClient httpclient = new DefaultHttpClient(); try {/* w w w . j a v a2 s .c om*/ httpclient.getCredentialsProvider().setCredentials(new AuthScope("133.13.162.149", 8080), new UsernamePasswordCredentials("43668069", "wf^O^2013")); HttpHost targetHost = new HttpHost("pt.3g.qq.com"); HttpHost proxy = new HttpHost("133.13.162.149", 8080); BasicClientCookie netscapeCookie = null; httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); // httpclient.getCookieStore().addCookie(netscapeCookie); httpclient.getParams().setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BROWSER_COMPATIBILITY); HttpGet httpget = new HttpGet("/"); httpget.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.162 Safari/535.19"); System.out.println("executing request: " + httpget.getRequestLine()); System.out.println("via proxy: " + proxy); System.out.println("to target: " + targetHost); HttpResponse response = httpclient.execute(targetHost, httpget); HttpEntity entity = response.getEntity(); System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); if (entity != null) { System.out.println("Response content length: " + entity.getContentLength()); } InputStream is = entity.getContent(); StringBuffer sb = new StringBuffer(200); byte data[] = new byte[65536]; int n = 1; do { n = is.read(data); if (n > 0) { sb.append(new String(data)); } } while (n > 0); // System.out.println(sb); EntityUtils.consume(entity); System.out.println("----------------------------------------"); Header[] headerlist = response.getAllHeaders(); for (int i = 0; i < headerlist.length; i++) { Header header = headerlist[i]; if (header.getName().equals("Set-Cookie")) { String setCookie = header.getValue(); String cookies[] = setCookie.split(";"); for (int j = 0; j < cookies.length; j++) { String cookie[] = cookies[j].split("="); CookieManager.cookie.put(cookie[0], cookie[1]); } } System.out.println(header.getName() + ":" + header.getValue()); } String sid = getSid(sb.toString(), "&"); System.out.println("sid: " + sid); httpclient = new DefaultHttpClient(); httpclient.getCredentialsProvider().setCredentials(new AuthScope("133.13.162.149", 8080), new UsernamePasswordCredentials("43668069", "wf^O^2013")); String url = Constant.openUrl + "&" + sid; targetHost = new HttpHost(url); httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); httpget = new HttpGet("/"); httpget.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.162 Safari/535.19"); Iterator it = CookieManager.cookie.entrySet().iterator(); while (it.hasNext()) { Map.Entry entry = (Map.Entry) it.next(); Object key = entry.getKey(); Object value = entry.getValue(); netscapeCookie = new BasicClientCookie((String) (key), (String) (value)); netscapeCookie.setVersion(0); netscapeCookie.setDomain(".qq.com"); netscapeCookie.setPath("/"); // httpclient.getCookieStore().addCookie(netscapeCookie); } response = httpclient.execute(targetHost, httpget); } finally { // When HttpClient instance is no longer needed, // shut down the connection manager to ensure // immediate deallocation of all system resources httpclient.getConnectionManager().shutdown(); } }
From source file:com.hilatest.httpclient.apacheexample.ClientExecuteProxy.java
public static void main(String[] args) throws Exception { // make sure to use a proxy that supports CONNECT HttpHost target = new HttpHost("issues.apache.org", 443, "https"); HttpHost proxy = new HttpHost("127.0.0.1", 8080, "http"); // general setup SchemeRegistry supportedSchemes = new SchemeRegistry(); // Register the "http" and "https" protocol schemes, they are // required by the default operator to look up socket factories. supportedSchemes.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); supportedSchemes.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); // prepare parameters HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, "UTF-8"); HttpProtocolParams.setUseExpectContinue(params, true); ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, supportedSchemes); DefaultHttpClient httpclient = new DefaultHttpClient(ccm, params); httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); HttpGet req = new HttpGet("/"); System.out.println("executing request to " + target + " via " + proxy); HttpResponse rsp = httpclient.execute(target, req); HttpEntity entity = rsp.getEntity(); System.out.println("----------------------------------------"); System.out.println(rsp.getStatusLine()); Header[] headers = rsp.getAllHeaders(); for (int i = 0; i < headers.length; i++) { System.out.println(headers[i]); }//from w ww.j a v a 2 s. com System.out.println("----------------------------------------"); if (entity != null) { System.out.println(EntityUtils.toString(entity)); } // When HttpClient instance is no longer needed, // shut down the connection manager to ensure // immediate deallocation of all system resources httpclient.getConnectionManager().shutdown(); }