【发布时间】:2013-04-07 18:42:51
【问题描述】:
我在我的 java 代码中使用 system.properties。 它在 Windows 7 操作系统上完美运行,但在 ubuntu12.04 上失败。
我在这两个地方都使用过tomcat。 在这方面的任何帮助都会有所帮助。
System.setProperty("http.proxyHost", proxyhost);
System.setProperty("http.proxyPort", proxyport);
String encoded = new String(encoder.encode(new String(username+":"+password).getBytes()));
uc.setRequestProperty("Proxy-Authorization", "Basic " + encoded);
例外: java.io.IOException:服务器返回 HTTP 响应代码:401 用于 URL:http://
【问题讨论】:
-
如果没有定义的字符集,
getBytes()方法将使用平台的默认字符集返回byte[]。在此过程中可能会丢失信息,并将错误的 base64 编码BASICauth 发送到代理。我会先检查一下。 -
谢谢大家只缺少 UTF-8