Java 创建可以在JAAS安全中传递用户名和密码的URLConnection

Java 创建可以在JAAS安全中传递用户名和密码的URLConnection,java,proxy,proxy-authentication,Java,Proxy,Proxy Authentication,嗨,我有如下类似的东西,可以建立URL连接 并检索数据。问题 是不是当我看到一页 首先需要身份验证 登录页面。我不知道该怎么做 在中传递用户名和密码 URLConnection。我正在访问一个站点 那就是使用JAAS认证 import java.net.URL; import java.net.URLConnection; ..... URL location = new URL("www.sampleURL.com"); URLConnection yc = location.openCo

嗨,我有如下类似的东西,可以建立URL连接 并检索数据。问题 是不是当我看到一页 首先需要身份验证 登录页面。我不知道该怎么做 在中传递用户名和密码 URLConnection。我正在访问一个站点 那就是使用JAAS认证

import java.net.URL;
import java.net.URLConnection;

.....

URL location = new URL("www.sampleURL.com");
URLConnection yc = location.openConnection();
BufferedReader in = new BufferedReader(
    new InputStreamReader(
    yc.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null) 
    data += inputLine + "\n";
in.close();
我试过这样的东西,但似乎不起作用

URL url = new URL("www.myURL.com");
URLConnection connection = url.openConnection();
String login = "username:password";
String encodedLogin = new BASE64Encoder().encodeBuffer(login.getBytes());
connection.setRequestProperty("Proxy-Authorization", "Basic " + encodedLogin);
请尝试“授权”,而不是“代理授权”。“Proxy Authorization”(代理授权)标头用于针对代理而不是您试图访问的实际web服务器进行身份验证