Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
linux mac上的Java URL连接_Java_Linux_Urlconnection - Fatal编程技术网

linux mac上的Java URL连接

linux mac上的Java URL连接,java,linux,urlconnection,Java,Linux,Urlconnection,我有以下代码 URL url = new URL("http://internalsite"); URLConnection conn = url.openConnection(); BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream())); String inputLine; System.out.println(conn); 当我打开这个窗

我有以下代码

URL url = new URL("http://internalsite");



URLConnection conn = url.openConnection();
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));

    String inputLine;
            System.out.println(conn);
当我打开这个窗口时,它工作正常 但是当我在Mac/Linux中打开它时,我得到了以下错误

java.io.IOException: Server returned HTTP response code: 401 for URL: http://internalsite
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1459)
你知道如何让它在linux/Mac中工作吗


谢谢

问题可能在于,在Windows上,您可以使用Windows登录自动通过站点身份验证(我不知道这是如何工作的),但在Linux或Mac上,您必须自己进行验证,至少在默认情况下是这样的


您的公司帮助台可能会以相同的方式设置您的Linux或Mac计算机以进行身份验证。。。当然,这只适用于那些特定的计算机。可能需要一个更通用的解决方案。

我使用了BasicAuthenticator

类基本身份验证程序扩展身份验证程序{

private  BasicAuthenticator() {
    // TODO Auto-generated constructor stub
}
public static BasicAuthenticator THIS = new BasicAuthenticator();

public static Authenticator getAutheticator(){
    return THIS;
}
  final static String USERNAME = "";
  final static String PASSWORD = "";

  @Override
  public PasswordAuthentication getPasswordAuthentication() {

    return new PasswordAuthentication(USERNAME, PASSWORD.toCharArray());
  }

}

如何配置此内部站点进行身份验证?响应代码401未经授权。检查WWW-Authenticate标头,您需要为url添加授权。或者你应该自己查一下HTTP 401。解决方案在于使用
java.net.Authenticator。