Java HTTP call for Sharepoint 2010 oData fails

I am calling Sharepoint 2010 oData with Java, which results in a 400 error. I can connect to the Sharepoint 2010 list in XML format using the same code (using NTLM).

I see a related HttpClient post using both SSL encryption and NTLM authentication , which talks about the same service (listdata.svc) and error 400.

Does anyone know which exact setting was used to fix the error in the above record? Does anyone know if they refer to .NET authorization rules in IIS?

We are using IIS 7.5.

My code is as follows:

String responseText = getAuthenticatedResponse(Url, domain, userName, password);
System.out.println("response: " + responseText);

This method uses Java 1.6 HTTPURLConnection:

private static String getAuthenticatedResponse(
    final String urlStr, final String domain, 
    final String userName, final String password) throws IOException {

    StringBuilder response = new StringBuilder();

    Authenticator.setDefault(new Authenticator() {

        @Override
        public PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication(
                domain + "\\" + userName, password.toCharArray());
        }
    });

    URL urlRequest = new URL(urlStr);
    HttpURLConnection conn = (HttpURLConnection) urlRequest.openConnection();
    conn.setDoOutput(true);
    conn.setDoInput(true);
    conn.setRequestMethod("GET");

    InputStream stream = conn.getInputStream();
    BufferedReader in = new BufferedReader(new InputStreamReader(stream));
    String str = "";
    while ((str = in.readLine()) != null) {
        response.append(str);
    }
    in.close();     

    return response.toString();
}

The error I am getting is:

Response Excerpt:
HTTP/1.1 400 Bad Request..Content-Type: application/xml
<message xml:lang="en-US">Media type requires a '/' character.  </message>

Microsoft. - , ?

!

0
2

. curl oData, .

:

> GET /sites/team-sites/operations/_vti_bin/listdata.svc/UBCal?=3 HTTP/1.1
> Authorization: NTLM <redacted>
> User-Agent: curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8r zlib/1.2.5
> Host: hostname
> Accept: */*

Java :

Accept: text/html, image/gif, image/jpeg, *;q=.2, */*; q=.2

"*/*" getAuthenticatedResponse :

 //Added for oData to work
conn.setRequestProperty("Accept", "*/*");

InputStream stream = conn.getInputStream();
....

400, sharepoint oData. , Java , .

+4

, , apache httpcomponents.

, NTLM , - - .

HttpContext localContext;

DefaultHttpClient httpclient = new DefaultHttpClient();
    httpclient.getAuthSchemes().register("ntlm", new NTLMSchemeFactory());
    NTCredentials creds = new NTCredentials(user_name, password, domain, domain);
    httpclient.getCredentialsProvider().setCredentials(AuthScope.ANY, creds);

    HttpHost target = new HttpHost(URL, Integer.parseInt(port), "http");
    localContext = new BasicHttpContext();

    HttpPost httppost = new HttpPost(list_name);
    httppost.setHeader("Accept", "application/json");
...
+1

All Articles