Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.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
到Sharepoint的HttpURLConnection不适用于Java 7,但适用于Java 5_Java_Rest_Sharepoint - Fatal编程技术网

到Sharepoint的HttpURLConnection不适用于Java 7,但适用于Java 5

到Sharepoint的HttpURLConnection不适用于Java 7,但适用于Java 5,java,rest,sharepoint,Java,Rest,Sharepoint,我有一段代码,可以使用HttpURLConnection将数据从SharePoint带到Unix。当我在服务器上使用Java1.5编译代码时,代码运行良好。数据显示在控制台上。但是当我尝试使用Java1.7时,同样的方法不起作用。返回的响应代码为“401”。消息是“未经授权的访问” 如果是某种身份验证问题,那么为什么java 1.5编译类中没有出现这种问题。是否有人知道HttpURLConnection库中有任何与此相关的更改。我在Java1.7中只发现了一个关于流长度限制的更改。谢谢你的帮助

我有一段代码,可以使用HttpURLConnection将数据从SharePoint带到Unix。当我在服务器上使用Java1.5编译代码时,代码运行良好。数据显示在控制台上。但是当我尝试使用Java1.7时,同样的方法不起作用。返回的响应代码为“401”。消息是“未经授权的访问”

如果是某种身份验证问题,那么为什么java 1.5编译类中没有出现这种问题。是否有人知道HttpURLConnection库中有任何与此相关的更改。我在Java1.7中只发现了一个关于流长度限制的更改。谢谢你的帮助

下面是代码的快照:

公共类RestMain{

    public static void main(String[] args)
    {


            Authenticator.setDefault (new Authenticator() {
                protected PasswordAuthentication getPasswordAuthentication() {
                            System.out.println(getRequestingScheme());
                    return new PasswordAuthentication ("Userid", "Password".toCharArray());
                }
            });

            try{
                    System.out.println(RestGet("SharePoint URL"));
            }
            catch(Exception e)
            {
                    System.out.println("error");
                    e.printStackTrace();
            }

    }


    public static String RestGet(String urlStr) throws IOException {
              URL url = new URL(urlStr);
              System.out.println("URL " + url.toString());
              HttpURLConnection conn =
                  (HttpURLConnection) url.openConnection();
              System.out.println("Response Code" + conn.getResponseCode());
              System.out.println("after connect");
              if (conn.getResponseCode() != 200) {
                      throw new IOException(conn.getResponseMessage());
              }
              conn.getResponseMessage();
              System.out.println("after Response");
              // Buffer the result into a string
              BufferedReader rd = new BufferedReader(
                  new InputStreamReader(conn.getInputStream()));
              StringBuilder sb = new StringBuilder();
              String line;
              while ((line = rd.readLine()) != null) {
                sb.append(line);
              }
              rd.close();
              conn.disconnect();
              System.out.println(sb);
              return (sb.toString().substring(1,500));
            }
}