2 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.openConnection();
BufferedReader in = new BufferedReader(
new InputStreamReader(
yc.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
data += inputLine + "\n";
in.close();
Run Code Online (Sandbox Code Playgroud)
我试过这样的东西,但似乎没有用......
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);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15986 次 |
| 最近记录: |