在Java的网络编程中,有时候内网服务器需要访问外网的网络资源,这时候就需要使用代理。

完整的代码下载:src.rar

一般系统在ie浏览器中设置的代理,java无法访问到,可通过以下代码进行:

    static {ProxySelector.setDefault(ProxyUtils.getProxySelectorOfIE());}

使用时,需要创建4个类,完整的代码如下:

package com.tool.utils;import java.lang.reflect.Method;/**** @since 2016-05-17*/
public final class StringUtils {private StringUtils() {}public static boolean isEmpty(String text) {return text == null || text.length() == 0;}public static boolean isNotEmpty(String text) {return !isEmpty(text);}public static String getGetterName(Method mtd) {String name = mtd.getName();if (name.startsWith("get")) {return Character.toLowerCase(name.charAt(3)) + name.substring(4);}if (name.startsWith("is")) {return Character.toLowerCase(name.charAt(2)) + name.substring(3);}return null;}public static String toGetterName(String name) {return "get" + Character.toUpperCase(name.charAt(0)) + name.substring(1);}}
package com.tool.utils;import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.ProxySelector;/*** 获得系统的IE代理设置的工具类** 用法是:* ProxySelector proxySelector = ProxyUtils.getProxySelectorOfIE();** 只能在windows系统中执行** @see ProxySelector*/
public class ProxyUtils {private static final String PATH_IE_SETTING = "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";private static final String BOOL_STR = "0x1";private static final String KEY_PROXY_SERVER = "ProxyServer";private static final String KEY_PROXY_ENABLE = "ProxyEnable";private static final String KEY_PROXY_OVERRIDE = "ProxyOverride";/*** 获得ie浏览器的代理,如果在linux环境下执行,会抛出异常** @return ie浏览器设置的默认代理,如果没开启则返回null*/public static Proxy getProxyOfIE() {checkWindows();try {if (isProxyEnable()) {String server = WinRegistry.valueForKey(WinRegistry.HKEY_CURRENT_USER, PATH_IE_SETTING, KEY_PROXY_SERVER);if (StringUtils.isNotEmpty(server)) {int i = server.indexOf(":");String host = server.substring(0, i);int port = Integer.parseInt(server.substring(i + 1));return new Proxy(Proxy.Type.HTTP, new InetSocketAddress(host, port));}}return null;} catch (Exception e) {throw new RuntimeException("failed to read the settings of the ie.", e);}}/*** 获得ie浏览器的ProxySelector,如果在linux环境下执行,会抛出异常** @see ProxySelector* @return ie浏览器设置的默认ProxySelector,如果没开启则返回{@code ProxySelector.getDefault()}*/public static ProxySelector getProxySelectorOfIE() {checkWindows();try{Proxy proxy = getProxyOfIE();String proxyOverride = WinRegistry.valueForKey(WinRegistry.HKEY_CURRENT_USER,PATH_IE_SETTING,KEY_PROXY_OVERRIDE);if(StringUtils.isEmpty(proxyOverride)){return new AddressProxySelector(proxy);}return new AddressProxySelector(proxyOverride,proxy);} catch (Exception e) {throw new RuntimeException("failed to read the settings of the ie.", e);}}private static boolean isProxyEnable() throws IllegalAccessException, IOException, InvocationTargetException {String proxyEnable = WinRegistry.valueForKey(WinRegistry.HKEY_CURRENT_USER,PATH_IE_SETTING,KEY_PROXY_ENABLE);return BOOL_STR.equalsIgnoreCase(proxyEnable);}private static void checkWindows() {String os = System.getProperty("os.name");if (!os.toLowerCase().startsWith("win")) {throw new IllegalStateException("this method can only run in windows os!");}}
}
package com.tool.utils;import java.io.IOException;
import java.net.Proxy;
import java.net.ProxySelector;
import java.net.SocketAddress;
import java.net.URI;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;public class AddressProxySelector extends ProxySelector {private String[] hosts;private Proxy proxy;public AddressProxySelector(Proxy proxy) {if (proxy == null) {proxy = Proxy.NO_PROXY;}this.proxy = proxy;}public AddressProxySelector(String host, Proxy proxy) {if (proxy == null) {proxy = Proxy.NO_PROXY;}this.hosts = host.split(";");this.proxy = proxy;}@Overridepublic List<Proxy> select(URI uri) {if (uri == null) {throw new IllegalArgumentException("URI can't be null.");}if (hosts == null) {return Collections.singletonList(this.proxy);}String uriHost = uri.getHost();if (Arrays.stream(hosts).anyMatch(host -> matches(host, uriHost))) {return Collections.singletonList(Proxy.NO_PROXY);}return Collections.singletonList(this.proxy);}private static boolean matches(String exp, String str) {if ("<local>".equals(exp)) {//匹配localhostreturn "localhost".equalsIgnoreCase(str) || "127.0.0.1".equals(str);}String[] arr1 = exp.split("\\.");String[] arr2 = str.split("\\.");if (arr1.length != arr2.length) {return false;}for (int i = 0; i < arr1.length; i++) {if (!"*".equals(arr1[1]) && !arr1[i].equals(arr2[i])) {return false;}}return true;}@Overridepublic void connectFailed(URI uri, SocketAddress sa, IOException ioe) {if (uri == null || sa == null || ioe == null) {throw new IllegalArgumentException("Arguments can't be null.");}}
}
package com.tool.utils;import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import java.util.prefs.Preferences;/*** Windows下读取注册表的工具类** 使用这些方法的示例如下:** 下面的方法从给定路径检索键的值:** String hex = WinRegistry.valueForKey(WinRegistry.HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\WindowsUpdate\\Auto Update", "AUOptions");** 此方法检索指定路径的所有数据(以键和值的形式):** Map<String, String> map = WinRegistry.valuesForPath(WinRegistry.HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\WSMAN");** 此方法从给定路径递归检索键的值:** String val = WinRegistry.valueForKeyPath(WinRegistry.HKEY_LOCAL_MACHINE, "System", "TypeID");** 并且这个方法递归地从给定路径中检索一个键的所有值:** List<String> list = WinRegistry.valuesForKeyPath( WinRegistry.HKEY_LOCAL_MACHINE, //HKEY "SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall", //path "DisplayName" //Key );** 在上面的代码中,我检索了Windows系统中所有已安装的软件名称。** 注意:请参阅这些方法的文档。** 这个检索给定路径的所有子键:** List<String> list3 = WinRegistry.subKeysForPath(WinRegistry.HKEY_CURRENT_USER, "Software");** 注意:在这个过程中,我只修改了阅读目的的方法,而不是像createKey、删除Key等写作目的的方法。它们仍然和我收到的一样。** https://cloud.tencent.com/developer/ask/43600*/
@SuppressWarnings("all")
public class WinRegistry {private static final int REG_SUCCESS = 0;private static final int REG_NOTFOUND = 2;private static final int KEY_READ = 0x20019;private static final int REG_ACCESSDENIED = 5;private static final int KEY_ALL_ACCESS = 0xf003f;public static final int HKEY_CLASSES_ROOT = 0x80000000;public static final int HKEY_CURRENT_USER = 0x80000001;public static final int HKEY_LOCAL_MACHINE = 0x80000002;private static final String CLASSES_ROOT = "HKEY_CLASSES_ROOT";private static final String CURRENT_USER = "HKEY_CURRENT_USER";private static final String LOCAL_MACHINE = "HKEY_LOCAL_MACHINE";private static Preferences userRoot = Preferences.userRoot();private static Preferences systemRoot = Preferences.systemRoot();private static Class<? extends Preferences> userClass = userRoot.getClass();private static Method regOpenKey = null;private static Method regCloseKey = null;private static Method regQueryValueEx = null;private static Method regEnumValue = null;private static Method regQueryInfoKey = null;private static Method regEnumKeyEx = null;private static Method regCreateKeyEx = null;private static Method regSetValueEx = null;private static Method regDeleteKey = null;private static Method regDeleteValue = null;static {try {regOpenKey = userClass.getDeclaredMethod("WindowsRegOpenKey", new Class[] {int.class, byte[].class, int.class});regOpenKey.setAccessible(true);regCloseKey = userClass.getDeclaredMethod("WindowsRegCloseKey", new Class[] {int.class});regCloseKey.setAccessible(true);regQueryValueEx = userClass.getDeclaredMethod("WindowsRegQueryValueEx", new Class[] {int.class, byte[].class});regQueryValueEx.setAccessible(true);regEnumValue = userClass.getDeclaredMethod("WindowsRegEnumValue", new Class[] {int.class, int.class, int.class});regEnumValue.setAccessible(true);regQueryInfoKey = userClass.getDeclaredMethod("WindowsRegQueryInfoKey1", new Class[] {int.class});regQueryInfoKey.setAccessible(true);regEnumKeyEx = userClass.getDeclaredMethod("WindowsRegEnumKeyEx", new Class[] {int.class, int.class, int.class});regEnumKeyEx.setAccessible(true);regCreateKeyEx = userClass.getDeclaredMethod("WindowsRegCreateKeyEx", new Class[] {int.class, byte[].class});regCreateKeyEx.setAccessible(true);regSetValueEx = userClass.getDeclaredMethod("WindowsRegSetValueEx", new Class[] {int.class, byte[].class, byte[].class});regSetValueEx.setAccessible(true);regDeleteValue = userClass.getDeclaredMethod("WindowsRegDeleteValue", new Class[] {int.class, byte[].class});regDeleteValue.setAccessible(true);regDeleteKey = userClass.getDeclaredMethod("WindowsRegDeleteKey", new Class[] {int.class, byte[].class});regDeleteKey.setAccessible(true);}catch (Exception e) {e.printStackTrace();}}/*** Reads value for the key from given path* @param hkey   HKEY_CURRENT_USER/HKEY_LOCAL_MACHINE* @param path* @param key* @return the value* @throws IllegalArgumentException* @throws IllegalAccessException* @throws InvocationTargetException* @throws IOException*/public static String valueForKey(int hkey, String path, String key)throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, IOException {if (hkey == HKEY_LOCAL_MACHINE) {return valueForKey(systemRoot, hkey, path, key);} else if (hkey == HKEY_CURRENT_USER) {return valueForKey(userRoot, hkey, path, key);} else {return valueForKey(null, hkey, path, key);}}/*** Reads all key(s) and value(s) from given path* @param hkey  HKEY_CURRENT_USER/HKEY_LOCAL_MACHINE* @param path* @return the map of key(s) and corresponding value(s)* @throws IllegalArgumentException* @throws IllegalAccessException* @throws InvocationTargetException* @throws IOException*/public static Map<String, String> valuesForPath(int hkey, String path)throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, IOException {if (hkey == HKEY_LOCAL_MACHINE) {return valuesForPath(systemRoot, hkey, path);} else if (hkey == HKEY_CURRENT_USER) {return valuesForPath(userRoot, hkey, path);} else {return valuesForPath(null, hkey, path);}}/*** Read all the subkey(s) from a given path* @param hkey  HKEY_CURRENT_USER/HKEY_LOCAL_MACHINE* @param path* @return the subkey(s) list* @throws IllegalArgumentException* @throws IllegalAccessException* @throws InvocationTargetException*/public static List<String> subKeysForPath(int hkey, String path)throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {if (hkey == HKEY_LOCAL_MACHINE) {return subKeysForPath(systemRoot, hkey, path);} else if (hkey == HKEY_CURRENT_USER) {return subKeysForPath(userRoot, hkey, path);} else {return subKeysForPath(null, hkey, path);}}/*** Create a key* @param hkey  HKEY_CURRENT_USER/HKEY_LOCAL_MACHINE* @param key* @throws IllegalArgumentException* @throws IllegalAccessException* @throws InvocationTargetException*/public static void createKey(int hkey, String key)throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {int [] ret;if (hkey == HKEY_LOCAL_MACHINE) {ret = createKey(systemRoot, hkey, key);regCloseKey.invoke(systemRoot, new Object[] { new Integer(ret[0]) });} else if (hkey == HKEY_CURRENT_USER) {ret = createKey(userRoot, hkey, key);regCloseKey.invoke(userRoot, new Object[] { new Integer(ret[0]) });} else {throw new IllegalArgumentException("hkey=" + hkey);}if (ret[1] != REG_SUCCESS) {throw new IllegalArgumentException("rc=" + ret[1] + "  key=" + key);}}/*** Write a value in a given key/value name* @param hkey* @param key* @param valueName* @param value* @throws IllegalArgumentException* @throws IllegalAccessException* @throws InvocationTargetException*/public static void writeStringValue(int hkey, String key, String valueName, String value)throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {if (hkey == HKEY_LOCAL_MACHINE) {writeStringValue(systemRoot, hkey, key, valueName, value);} else if (hkey == HKEY_CURRENT_USER) {writeStringValue(userRoot, hkey, key, valueName, value);} else {throw new IllegalArgumentException("hkey=" + hkey);}}/*** Delete a given key* @param hkey* @param key* @throws IllegalArgumentException* @throws IllegalAccessException* @throws InvocationTargetException*/public static void deleteKey(int hkey, String key)throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {int rc = -1;if (hkey == HKEY_LOCAL_MACHINE) {rc = deleteKey(systemRoot, hkey, key);} else if (hkey == HKEY_CURRENT_USER) {rc = deleteKey(userRoot, hkey, key);}if (rc != REG_SUCCESS) {throw new IllegalArgumentException("rc=" + rc + "  key=" + key);}}/*** delete a value from a given key/value name* @param hkey* @param key* @param value* @throws IllegalArgumentException* @throws IllegalAccessException* @throws InvocationTargetException*/public static void deleteValue(int hkey, String key, String value)throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {int rc = -1;if (hkey == HKEY_LOCAL_MACHINE) {rc = deleteValue(systemRoot, hkey, key, value);} else if (hkey == HKEY_CURRENT_USER) {rc = deleteValue(userRoot, hkey, key, value);}if (rc != REG_SUCCESS) {throw new IllegalArgumentException("rc=" + rc + "  key=" + key + "  value=" + value);}}// =====================private static int deleteValue(Preferences root, int hkey, String key, String value)throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {int[] handles = (int[]) regOpenKey.invoke(root, new Object[] {new Integer(hkey), toCstr(key), new Integer(KEY_ALL_ACCESS)});if (handles[1] != REG_SUCCESS) {return handles[1];                                  // can be REG_NOTFOUND, REG_ACCESSDENIED}int rc =((Integer) regDeleteValue.invoke(root, new Object[] {new Integer(handles[0]), toCstr(value)})).intValue();regCloseKey.invoke(root, new Object[] { new Integer(handles[0])});return rc;}private static int deleteKey(Preferences root, int hkey, String key)throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {int rc =((Integer) regDeleteKey.invoke(root, new Object[] {new Integer(hkey), toCstr(key)})).intValue();return rc;                                                  // can REG_NOTFOUND, REG_ACCESSDENIED, REG_SUCCESS}private static String valueForKey(Preferences root, int hkey, String path, String key)throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, IOException {int[] handles = (int[]) regOpenKey.invoke(root, new Object[] {new Integer(hkey), toCstr(path), new Integer(KEY_READ)});if (handles[1] != REG_SUCCESS) {throw new IllegalArgumentException("The system can not find the specified path: '"+getParentKey(hkey)+"\\"+path+"'");}byte[] valb = (byte[]) regQueryValueEx.invoke(root, new Object[] {new Integer(handles[0]), toCstr(key)});regCloseKey.invoke(root, new Object[] {new Integer(handles[0])});return (valb != null ? parseValue(valb) : queryValueForKey(hkey, path, key));}private static String queryValueForKey(int hkey, String path, String key) throws IOException {return queryValuesForPath(hkey, path).get(key);}private static Map<String,String> valuesForPath(Preferences root, int hkey, String path)throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, IOException {HashMap<String, String> results = new HashMap<String,String>();int[] handles = (int[]) regOpenKey.invoke(root, new Object[] {new Integer(hkey), toCstr(path), new Integer(KEY_READ)});if (handles[1] != REG_SUCCESS) {throw new IllegalArgumentException("The system can not find the specified path: '"+getParentKey(hkey)+"\\"+path+"'");}int[] info = (int[]) regQueryInfoKey.invoke(root, new Object[] {new Integer(handles[0])});int count = info[2];                            // Fixed: info[0] was being used hereint maxlen = info[4];                           // while info[3] was being used here, causing wrong resultsfor(int index=0; index<count; index++) {byte[] valb = (byte[]) regEnumValue.invoke(root, new Object[] {new Integer(handles[0]), new Integer(index), new Integer(maxlen + 1)});String vald = parseValue(valb);if(valb == null || vald.isEmpty()) {return queryValuesForPath(hkey, path);}results.put(vald, valueForKey(root, hkey, path, vald));}regCloseKey.invoke(root, new Object[] {new Integer(handles[0])});return results;}/*** Searches recursively into the path to find the value for key. This method gives* only first occurrence value of the key. If required to get all values in the path* recursively for this key, then {@link #valuesForKeyPath(int hkey, String path, String key)}* should be used.* @param hkey* @param path* @param key* @param list* @return the value of given key obtained recursively* @throws IllegalArgumentException* @throws IllegalAccessException* @throws InvocationTargetException* @throws IOException*/public static String valueForKeyPath(int hkey, String path, String key)throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, IOException {String val;try {val = valuesForKeyPath(hkey, path, key).get(0);} catch(IndexOutOfBoundsException e) {throw new IllegalArgumentException("The system can not find the key: '"+key+"' after "+ "searching the specified path: '"+getParentKey(hkey)+"\\"+path+"'");}return val;}/*** Searches recursively into given path for particular key and stores obtained value in list* @param hkey* @param path* @param key* @param list* @return list containing values for given key obtained recursively* @throws IllegalArgumentException* @throws IllegalAccessException* @throws InvocationTargetException* @throws IOException*/public static List<String> valuesForKeyPath(int hkey, String path, String key)throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, IOException {List<String> list = new ArrayList<String>();if (hkey == HKEY_LOCAL_MACHINE) {return valuesForKeyPath(systemRoot, hkey, path, key, list);} else if (hkey == HKEY_CURRENT_USER) {return valuesForKeyPath(userRoot, hkey, path, key, list);} else {return valuesForKeyPath(null, hkey, path, key, list);}}private static List<String> valuesForKeyPath(Preferences root, int hkey, String path, String key, List<String> list)throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, IOException {if(!isDirectory(root, hkey, path)) {takeValueInListForKey(hkey, path, key, list);} else {List<String> subKeys = subKeysForPath(root, hkey, path);for(String subkey: subKeys) {String newPath = path+"\\"+subkey;if(isDirectory(root, hkey, newPath)) {valuesForKeyPath(root, hkey, newPath, key, list);}takeValueInListForKey(hkey, newPath, key, list);}}return list;}/*** Takes value for key in list* @param hkey* @param path* @param key* @param list* @throws IllegalArgumentException* @throws IllegalAccessException* @throws InvocationTargetException* @throws IOException*/private static void takeValueInListForKey(int hkey, String path, String key, List<String> list)throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, IOException {String value = valueForKey(hkey, path, key);if(value != null) {list.add(value);}}/*** Checks if the path has more subkeys or not* @param root* @param hkey* @param path* @return true if path has subkeys otherwise false* @throws IllegalArgumentException* @throws IllegalAccessException* @throws InvocationTargetException*/private static boolean isDirectory(Preferences root, int hkey, String path)throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {return !subKeysForPath(root, hkey, path).isEmpty();}private static List<String> subKeysForPath(Preferences root, int hkey, String path)throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {List<String> results = new ArrayList<String>();int[] handles = (int[]) regOpenKey.invoke(root, new Object[] {new Integer(hkey), toCstr(path), new Integer(KEY_READ)});if (handles[1] != REG_SUCCESS) {throw new IllegalArgumentException("The system can not find the specified path: '"+getParentKey(hkey)+"\\"+path+"'");}int[] info = (int[]) regQueryInfoKey.invoke(root, new Object[] {new Integer(handles[0])});int count  = info[0]; // Fix: info[2] was being used here with wrong results. Suggested by davenpcj, confirmed by Petrucioint maxlen = info[3]; // value length maxfor(int index=0; index<count; index++) {byte[] valb = (byte[]) regEnumKeyEx.invoke(root, new Object[] {new Integer(handles[0]), new Integer(index), new Integer(maxlen + 1)});results.add(parseValue(valb));}regCloseKey.invoke(root, new Object[] {new Integer(handles[0])});return results;}private static int [] createKey(Preferences root, int hkey, String key)throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {return (int[]) regCreateKeyEx.invoke(root, new Object[] {new Integer(hkey), toCstr(key)});}private static void writeStringValue(Preferences root, int hkey, String key, String valueName, String value)throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {int[] handles = (int[]) regOpenKey.invoke(root, new Object[] {new Integer(hkey), toCstr(key), new Integer(KEY_ALL_ACCESS)});regSetValueEx.invoke(root, new Object[] {new Integer(handles[0]), toCstr(valueName), toCstr(value)});regCloseKey.invoke(root, new Object[] {new Integer(handles[0])});}/*** Makes cmd query for the given hkey and path then executes the query* @param hkey* @param path* @return the map containing all results in form of key(s) and value(s) obtained by executing query* @throws IOException*/private static Map<String, String> queryValuesForPath(int hkey, String path) throws IOException {String line;StringBuilder builder = new StringBuilder();Map<String, String> map = new HashMap<String, String>();Process process = Runtime.getRuntime().exec("reg query \""+getParentKey(hkey)+"\\" + path + "\"");BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));while((line = reader.readLine()) != null) {if(!line.contains("REG_")) {continue;}StringTokenizer tokenizer = new StringTokenizer(line, " \t");while(tokenizer.hasMoreTokens()) {String token = tokenizer.nextToken();if(token.startsWith("REG_")) {builder.append("\t ");} else {builder.append(token).append(" ");}}String[] arr = builder.toString().split("\t");map.put(arr[0].trim(), arr[1].trim());builder.setLength(0);}return map;}/*** Determines the string equivalent of hkey* @param hkey* @return string equivalent of hkey*/private static String getParentKey(int hkey) {if(hkey == HKEY_CLASSES_ROOT) {return CLASSES_ROOT;} else if(hkey == HKEY_CURRENT_USER) {return CURRENT_USER;} else if(hkey == HKEY_LOCAL_MACHINE) {return LOCAL_MACHINE;}return null;}/***Intern method which adds the trailing \0 for the handle with java.dll* @param str String* @return byte[]*/private static byte[] toCstr(String str) {if(str == null) {str = "";}return (str += "\0").getBytes();}/*** Method removes the trailing \0 which is returned from the java.dll (just if the last sign is a \0)* @param buf the byte[] buffer which every read method returns* @return String a parsed string without the trailing \0*/private static String parseValue(byte buf[]) {if(buf == null) {return null;}String ret = new String(buf);if(ret.charAt(ret.length()-1) == '\0') {return ret.substring(0, ret.length()-1);}return ret;}
}

Java中使用IE Proxy代理的方法相关推荐

  1. java中各种使用设置代理的方法

    1.http代理 package main.java.com.example; import org.apache.http.HttpHost; import org.apache.http.clie ...

  2. java中为什么要使用代理

    引入代理: 我们为什么要引入java的代理,除了当前类能够提供的功能外,我们还需要补充一些其他功能. 最容易想到的情况就是权限过滤,我有一个类做某项业务,但是由于安全原因只有某些用户才可以调用这个类, ...

  3. java中InvocationHandler 用于实现代理。

    以下的内容部分参考了网络上的内容,在此对原作者表示感谢! Java中动态代理的实现,关键就是这两个东西:Proxy.InvocationHandler,下面从InvocationHandler接口中的 ...

  4. java语言 文件上传,java中实现文件上传的方法

    java中实现文件上传的方法 发布时间:2020-06-19 10:29:11 来源:亿速云 阅读:86 作者:Leah 这篇文章给大家分享的是java中实现文件上传的方法,相信大部分人都还没学会这个 ...

  5. Java中创建数组的几种方法

    Java中创建数组的几种方法 public static void main(String[] args) { //创建数组的第一种方法 int[] arr=new int[6]; int intVa ...

  6. 在 Java 中初始化 List 的五种方法

    转载自  在 Java 中初始化 List 的五种方法 Java 中经常需要使用到 List,下面简单介绍几种常见的初始化方式. 1.构造 List 后使用 List.add 初始化 List< ...

  7. 高级 | Java中获取类名的3种方法

    转载自 高级 | Java中获取类名的3种方法 获取类名的方法 Java 中获取类名的方式主要有以下三种. getName() 返回的是虚拟机里面的class的类名表现形式. getCanonical ...

  8. 谈谈java中遍历Map的几种方法

    java中的map遍历有多种方法,从最早的Iterator,到java5支持的foreach,再到java8 Lambda,让我们一起来看下具体的用法以及各自的优缺点 先初始化一个map public ...

  9. Java 中 List 分片的 5 种方法!

    作者 | 王磊 来源 | Java中文社群(ID:javacn666) 转载请联系授权(微信ID:GG_Stone) 前些天在实现 MyBatis 批量插入时遇到了一个问题,当批量插入的数据量比较大时 ...

最新文章

  1. 赵立新主持机器人_《档案》第二任主持人赵立新:我是石凉接班人
  2. 【Android 应用开发】Canvas 精准绘制文字 ( 文本边界坐标解析 | 绘图位置 )
  3. 《用户故事与敏捷方法》阅读笔记一
  4. oracle数据库倒顺,mysql常用命令
  5. 多进程Socket_Server
  6. BZOJ4107 : [Wf2015]Asteroids
  7. 中国连锁餐饮企业的资本之路
  8. 售票系统的组件图和部署图_实物图+电气图讲解:教你学会看配电系统图,值得收藏!...
  9. 苹果A13和A11性能差距有多大?
  10. html5只能django来写if吗,(4)Django学习——模板标签定义及语法:for循环,if判断,页面跳转,开启关闭自动转义,ur...
  11. c# npoi 打开已经存在excel_用了这个jupyter插件,我已经半个月没打开过excel了
  12. lisp天正图元位置修改_关于图元改层的,请求大佬帮助 - AutoLISP/Visual LISP 编程技术 - CAD论坛 - 明经CAD社区 - Powered by Discuz!...
  13. 10月份都有哪些好看的韩剧?
  14. Leetcode 318. Maximum Product of Word Lengths
  15. 推荐两款github敏感信息搜集工具(gsil、gshark)
  16. c语言头文件有哪些intr,有没有大神帮帮忙
  17. kubectl源码分析之rollout history
  18. 2021-01-16 SONiC系统管理10 Telemetry
  19. sql服务器状态已停止,SQL SERVER 2008 SSMS - SQL Server Management Studio 已停止工作
  20. IOS开发入门之二——第一个App

热门文章

  1. 10款最佳的Linux文件比较工具
  2. 【游戏开发教程】Unity Cinemachine快速上手,详细案例讲解(虚拟相机系统 新发出品 良心教程)
  3. Django模板系统(十分 非常详细)
  4. 【华为机试真题Python】高矮个子排队
  5. opencv:log()函数
  6. Navicat导出数据库设计文档
  7. 数据库设计文档生成工具类
  8. 【Java设计模式 规范与重构】 六 代码重构小结
  9. 手机直播系统开发中关于iOS获取图形验证码功能
  10. System.ArgumentNullException: Value cannot be null. (Parameter connectionString)at Microsoft.Entit