[英]URL Class in java
I am using this program in JAVA to get a csv file from the specified URL, but only problem is that it requires username and password that I know, how can I modify this program to include username and password? 我正在JAVA中使用此程序从指定的URL获取一个csv文件,但是唯一的问题是它需要我知道的用户名和密码,如何修改此程序以包括用户名和密码?
public class TestGetCSV {
public static void main(String[] args) {
try {
URL url12 = new URL("https://wd5-impl-services1.workday.com/ccx/service/customreport2/yahoo3/ISU-YINT061-ProjectsFE/YINT061.05-getWorkersForOpenText?format=csv" );
URLConnection urlConn = url12.openConnection();
HttpURLConnection conn = (HttpURLConnection)urlConn;
conn.setInstanceFollowRedirects( false );
InputStreamReader inStream = new InputStreamReader(urlConn.getInputStream());
BufferedReader buff= new BufferedReader(inStream);
String content2 = buff.readLine();
while (content2 !=null) {
System.out.println(content2);
content2 = buff.readLine();
}
}
catch (Exception e){
e.printStackTrace();
}
}
}
As this is basic authentication based upon HTTP headers you can just open the URL 由于这是基于HTTP标头的基本身份验证,因此您只需打开URL
https://<username>:<password>@wd5-impl-services1.workday.com/ccx/service/customreport2/yahoo3/ISU-YINT061-ProjectsFE/YINT061.05-getWorkersForOpenText?format=csv
instead I believe. 相反,我相信。
However, please keep in mind that this way your credentials are supplied in plaintext. 但是,请记住,这种方式以纯文本形式提供您的凭据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.