URL问题(100分) URL url = new URL("http://user:[email protected]/index.html");URLConnection con = url.openConnection(); 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://用户名:密码@www.xxx.com:端口号/index.html确定用户名和密码正确吗 wwangl(???) 的方法应该可以解决问题的你按 wwangl(???) 所说的链接可以直接访问吗? 我在IIS的虚拟目录的属性中,修改它的目录安全性为“基本验证” 可以的,在浏览器中使用http://user:[email protected]/index.html可以我的程序代码如下:URL url = new URL(http://user:[email protected]/index.html);URLConnection con = url.openConnection();InputStream is = con.getInputStream();DataInputStream filedata = new DataInputStream(is);BufferedReader d = new BufferedReader(new InputStreamReader(filedata));while ((fileline = d.readLine()) != null) { System.out.println(fileline);} 在建立连接之后,发送请求之前加入下面的语句。此种方式为Basic认证。String authString = "user:password"; String auth ="Basic "+new sun.misc.BASE64Encoder().encode(authString.getBytes()); System.out.println("AuthString : "+auth); urlConn.setRequestProperty( "Proxy-Authorization", auth ); 建立连接之后,发送请求之前就是指openConnection之前吗? 程序改为如下:还是不行(URL url = new URL(http[0].toString());URLConnection con = url.openConnection();String authString = "user:password";String auth ="Basic "+new sun.misc.BASE64Encoder().encode(authString.getBytes());System.out.println("AuthString : "+auth);con.setRequestProperty( "Proxy-Authorization", auth );con.connect();InputStream is = con.getInputStream();DataInputStream filedata = new DataInputStream(is);BufferedReader d = new BufferedReader(new InputStreamReader(filedata));while ((fileline = d.readLine()) != null) { System.out.println(fileline);} 我的写法是这样的,我没有IIS环境,但在我的Domino下通过package congtest;import java.io.*;import java.net.*;public class TestURL{ public static void main(String[] args) throws Exception{ URL url = new URL("http://182.2.160.93"); URLConnection con = url.openConnection(); String authString = "user:password"; String auth ="Basic "+new sun.misc.BASE64Encoder().encode(authString.getBytes()); con.setRequestProperty("Authorization", auth); InputStream is = con.getInputStream(); DataInputStream filedata = new DataInputStream(is); BufferedReader d = new BufferedReader(new InputStreamReader(filedata)); String fileline = null; while ((fileline = d.readLine()) != null) { System.out.println(fileline); } }} 哦,对。Proxy-Authorization是对代理服务器的。Authorization是直接的。谢谢 littlecong(虫子) SpringLayout问题 新手求助 谁来帮我讲解一下这道题~~~谢谢 怎么样动态得到资源文件(资源文件的获取) 如何用java打开文件的问题 偶打的一个乘法口诀形式,请大家指点!用数组怎么实现呢? 关于数组的方法调用 求<java编程思想第三版>光盘代码 《Design Patterns Explained》设计模式精解(PDF 文档,RAR 6,962,472 bytes) 关于java反编译 请问怎么把“1/40000”这个有理数形式的字符串转成double型 各位大侠,问一个弱弱的问题! 如何两个form 参数传递
确定用户名和密码正确吗
你按 wwangl(???) 所说的链接可以直接访问吗?
我的程序代码如下:
URL url = new URL(http://user:[email protected]/index.html);
URLConnection con = url.openConnection();
InputStream is = con.getInputStream();
DataInputStream filedata = new DataInputStream(is);
BufferedReader d = new BufferedReader(new InputStreamReader(filedata));
while ((fileline = d.readLine()) != null) {
System.out.println(fileline);
}
String authString = "user:password";
String auth ="Basic "+new sun.misc.BASE64Encoder().encode(authString.getBytes());
System.out.println("AuthString : "+auth);
urlConn.setRequestProperty( "Proxy-Authorization", auth );
URLConnection con = url.openConnection();String authString = "user:password";
String auth ="Basic "+new sun.misc.BASE64Encoder().encode(authString.getBytes());
System.out.println("AuthString : "+auth);
con.setRequestProperty( "Proxy-Authorization", auth );con.connect();InputStream is = con.getInputStream();
DataInputStream filedata = new DataInputStream(is);
BufferedReader d = new BufferedReader(new InputStreamReader(filedata));
while ((fileline = d.readLine()) != null) {
System.out.println(fileline);
}
import java.net.*;public class TestURL{
public static void main(String[] args) throws Exception{
URL url = new URL("http://182.2.160.93");
URLConnection con = url.openConnection();
String authString = "user:password";
String auth ="Basic "+new sun.misc.BASE64Encoder().encode(authString.getBytes());
con.setRequestProperty("Authorization", auth);
InputStream is = con.getInputStream();
DataInputStream filedata = new DataInputStream(is);
BufferedReader d = new BufferedReader(new InputStreamReader(filedata));
String fileline = null;
while ((fileline = d.readLine()) != null) {
System.out.println(fileline);
}
}
}
Authorization是直接的。
谢谢 littlecong(虫子)