---
title: "在java代码中设置代理使用代理服务器-我的读书笔记-iteye技术网站"
author: "yng02yng"
date: "2012-01-11T12:01:26Z"
tags: []
categories: ["非技术"]
slug: "java-iteye"
draft: false
lastmod: "2012-01-11T12:01:26Z"
id: 1340972
url: "https://yng02yng.iteye.com/blog/1340972"
---


在java代码中设置代理使用代理服务器-我的读书笔记-iteye技术网站 
2011年07月01日
　　import java.net.*; import java.io.*; public class URLReader { public static void main(String[] args) throws Exception { // Configure proxy ... System.setProperty("http.proxySet", "true"); System.setProperty("http.proxyHost", "proxy.nnnsssfff.com"); System.setProperty("http.proxyPort", "8080"); System.setProperty("http.proxyType", "4"); String proxyUser = "lv.hq", proxyPassword = "自己的密码！！！！！！！！！！！"; // Open URL ... URL url = new URL("http://www.google.com/"); URLConnection con = url.openConnection(); // proxy user and pass con.setRequestProperty("Proxy-Authorization", "Basic " + new sun.misc.BASE64Encoder() .encode((proxyUser + ":" + proxyPassword).getBytes())); BufferedReader in = new BufferedReader(new InputStreamReader(con .getInputStream())); // Read it ... String inputLine; while ((inputLine = in.readLine()) != null) System.out.println(inputLine); in.close(); } } 
　　
　　
