package src.test;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import sun.misc.BASE64Encoder;
public class URLTest {
public static void main(String[] args){
try{
System.setProperty("proxySet", "true");
System.setProperty("http.proxyHost", "11.0.1.210");
System.setProperty("http.proxyPort", "8080");
URL u = new URL("http://www.baidu.com");
HttpURLConnection conn = (HttpURLConnection)u.openConnection();
String authentication = "caixian2:96191264";
String encodedLogin = new BASE64Encoder().encodeBuffer(authentication.getBytes());
conn.setRequestProperty("Proxy-Authorization", "Basic " + encodedLogin);
conn.connect();
int length = conn.getContentLength();
System.out.println(length);
InputStream is = conn.getInputStream();
byte[] b = new byte[4 * 1024];
is.read(b);
for(int i = 0; i < b.length; i++){
System.out.print((char)b[i]);
}
}catch(IOException e){
e.printStackTrace();
}
}
} package src.test;import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;import sun.misc.BASE64Encoder;public class URLTest {
public static void main(String[] args){
try{
System.setProperty("proxySet", "true");
System.setProperty("http.proxyHost", "11.0.1.210");
System.setProperty("http.proxyPort", "8080");
URL u = new URL("http://www.baidu.com");
HttpURLConnection conn = (HttpURLConnection)u.openConnection(); String authentication = "caixian2:96191264";
String encodedLogin = new BASE64Encoder().encodeBuffer(authentication.getBytes());
conn.setRequestProperty("Proxy-Authorization", "Basic " + encodedLogin);
conn.connect();
int length = conn.getContentLength();
System.out.println(length);
InputStream is = conn.getInputStream();
byte[] b = new byte[4 * 1024];
is.read(b);
for(int i = 0; i < b.length; i++){
System.out.print((char)b[i]);
}
}catch(IOException e){
e.printStackTrace();
}
}
}我在单位的内部网通过代理设置上网,现在想写个程序来访问外部网,在网上找了哈偶都资料,我个人感觉代码应该没有错误啊,可是就是报异常,如下: java.lang.IllegalArgumentException: Illegal character(s) in message header value: Basic Y2FpeGlhbjI6OTYxOTEyNjQ=
at sun.net.www.protocol.http.HttpURLConnection.checkMessageHeader(HttpURLConnection.java:200)
at sun.net.www.protocol.http.HttpURLConnection.setRequestProperty(HttpURLConnection.java:1553)
at src.test.URLTest.main(URLTest.java:23)
Exception in thread "main" java.lang.IllegalArgumentException: Illegal character(s) in message header value: Basic Y2FpeGlhbjI6OTYxOTEyNjQ= at sun.net.www.protocol.http.HttpURLConnection.checkMessageHeader(HttpURLConnection.java:200)
at sun.net.www.protocol.http.HttpURLConnection.setRequestProperty(HttpURLConnection.java:1553)
at src.test.URLTest.main(URLTest.java:23)
Exception in thread "main"
高人们帮个忙,看看我哪里还写错了,非常感谢!!!
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import sun.misc.BASE64Encoder;
public class URLTest {
public static void main(String[] args){
try{
System.setProperty("proxySet", "true");
System.setProperty("http.proxyHost", "11.0.1.210");
System.setProperty("http.proxyPort", "8080");
URL u = new URL("http://www.baidu.com");
HttpURLConnection conn = (HttpURLConnection)u.openConnection();
String authentication = "caixian2:96191264";
String encodedLogin = new BASE64Encoder().encodeBuffer(authentication.getBytes());
conn.setRequestProperty("Proxy-Authorization", "Basic " + encodedLogin);
conn.connect();
int length = conn.getContentLength();
System.out.println(length);
InputStream is = conn.getInputStream();
byte[] b = new byte[4 * 1024];
is.read(b);
for(int i = 0; i < b.length; i++){
System.out.print((char)b[i]);
}
}catch(IOException e){
e.printStackTrace();
}
}
} package src.test;import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;import sun.misc.BASE64Encoder;public class URLTest {
public static void main(String[] args){
try{
System.setProperty("proxySet", "true");
System.setProperty("http.proxyHost", "11.0.1.210");
System.setProperty("http.proxyPort", "8080");
URL u = new URL("http://www.baidu.com");
HttpURLConnection conn = (HttpURLConnection)u.openConnection(); String authentication = "caixian2:96191264";
String encodedLogin = new BASE64Encoder().encodeBuffer(authentication.getBytes());
conn.setRequestProperty("Proxy-Authorization", "Basic " + encodedLogin);
conn.connect();
int length = conn.getContentLength();
System.out.println(length);
InputStream is = conn.getInputStream();
byte[] b = new byte[4 * 1024];
is.read(b);
for(int i = 0; i < b.length; i++){
System.out.print((char)b[i]);
}
}catch(IOException e){
e.printStackTrace();
}
}
}我在单位的内部网通过代理设置上网,现在想写个程序来访问外部网,在网上找了哈偶都资料,我个人感觉代码应该没有错误啊,可是就是报异常,如下: java.lang.IllegalArgumentException: Illegal character(s) in message header value: Basic Y2FpeGlhbjI6OTYxOTEyNjQ=
at sun.net.www.protocol.http.HttpURLConnection.checkMessageHeader(HttpURLConnection.java:200)
at sun.net.www.protocol.http.HttpURLConnection.setRequestProperty(HttpURLConnection.java:1553)
at src.test.URLTest.main(URLTest.java:23)
Exception in thread "main" java.lang.IllegalArgumentException: Illegal character(s) in message header value: Basic Y2FpeGlhbjI6OTYxOTEyNjQ= at sun.net.www.protocol.http.HttpURLConnection.checkMessageHeader(HttpURLConnection.java:200)
at sun.net.www.protocol.http.HttpURLConnection.setRequestProperty(HttpURLConnection.java:1553)
at src.test.URLTest.main(URLTest.java:23)
Exception in thread "main"
高人们帮个忙,看看我哪里还写错了,非常感谢!!!
解决方案 »
- mysql数据库连接不上,报错:com.mysql.jdbc.CommunicationsException
- 修改属性文件的问题?急救,高手们请帮帮我!
- JScrollPane问题,请达人们瞧一瞧!
- 配置default.properties文件问题
- Oracle求助
- 关于generics java
- 请问怎么将变量值用于java中的sql语句中??
- 为什么在IE中嵌入Applet后,运行的效果不一样?
- rongrongGsr() 请进来看一下
- 我是一个java 初学者,请问在那里有java文档下载较好的网站?(NULL〕
- unsupported encoding cp1386
- 问个关于jre的问题
是和 Basic Y2FpeGlhbjI6OTYxOTEyNjQ= 有关嘛?
这一行的时候就卡住了呢,一直都不向下走!!!