我可以使用基本身份验证通过GET-REST请求从JAVA访问SharePoint 2010吗?

我可以使用基本身份验证通过GET-REST请求从JAVA访问SharePoint 2010吗?,java,rest,authentication,sharepoint-2010,httpurlconnection,Java,Rest,Authentication,Sharepoint 2010,Httpurlconnection,我正在尝试使用REST请求从SharePoint 2010获取数据列表,但出现以下异常: [err]java.io.IOException:未经授权 我的代码是: public static String httpGet(String urlStr) throws IOException { URL url = new URL(urlStr); String domain = "theuserdomain"; String userna

我正在尝试使用REST请求从SharePoint 2010获取数据列表,但出现以下异常:

[err]java.io.IOException:未经授权

我的代码是:

public static String httpGet(String urlStr) throws IOException {

      URL url = new URL(urlStr);          
      String domain = "theuserdomain"; 
      String username ="myusername";
      String password = "mypassword";
      String credentials = domain+"\\"+username + ":" + password;
      String encoding = new sun.misc.BASE64Encoder().encode(credentials.getBytes());

      HttpURLConnection conn = (HttpURLConnection) url.openConnection();
      conn.setRequestProperty("Authorization", "Basic " + encoding);
      conn.connect();

      if (conn.getResponseCode() != 200) {
        throw new IOException(conn.getResponseMessage());
      }

      // 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();
      return sb.toString();
    }

我认为我的问题是我没有正确设置用户域…如何在我的请求中设置它?

使用NTLM身份验证解决:

        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpGet getRequest = new HttpGet(webPage);

        NTCredentials credentials = new NTCredentials(username, password, workstation, domain);


        httpClient.getCredentialsProvider().setCredentials(new AuthScope(server,port), credentials);

        HttpResponse response = httpClient.execute(getRequest);

未经身份验证时,如何填写浏览器对话框?这是否适用于Firefox和Chrome,还是仅适用于Internet Explorer。如果没有,可能SharePoint不使用基本身份验证,而是使用类似NTLM Chalenge/Response的功能…我已经尝试使用Firefox、Explorer和Chrome,我可以看到响应。在浏览器身份验证表单中,我写了:USERNAME:theuserdomain\myusername密码:mypassword,它可以工作!基本身份验证是否正确?您可以跟踪传出/传入流量,例如在Chrome Web Developer或FireFox Firebug中,并将浏览器设置的标题与您的进行比较。使用Chrome:Accept:text/html、application/xhtml+xml、application/xml;q=0.9,图像/webp,/;q=0。‌​8接受编码:gzip、deflate、sdch接受语言:it it、it;q=0.8,在美国;q=0.6,en;q=0.4授权:NTLM