title: Java HTTP call to Sharepoint 2010 oData fails
body: <p>I am calling a Sharepoint 2010 oData service from Java which is resulting in a 400 error. I can connect to a Sharepoint 2010 list in XML format via the same code (using NTLM) successfully. </p>
  
  <p>I see a related post <a href="https://stackoverflow.com/questions/9714615/httpclient-using-both-ssl-encryption-and-ntlm-authentication-fails">HttpClient using both SSL encryption and NTLM authentication fails</a> which talks of the same service (listdata.svc) and the 400 error.</p>
  
  <p>Does anyone know what exact setting was used to resolve the error in the post above? Does anyone know if they are referring to the .NET Authorization Rules in IIS?</p>
  
  <p>We are using IIS 7.5.</p>
  
  <p>My code looks like this:</p>
  
  <pre><code>String responseText = getAuthenticatedResponse(Url, domain, userName, password);
  System.out.println("response: " + responseText);
  </code></pre>
  
  <p>The method uses uses Java 1.6 HTTPURLConnection:</p>
  
  <pre><code>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();
  }
  </code></pre>
  
  <p>The error I get is :</p>
  
  <pre><code>Response Excerpt:
  HTTP/1.1 400 Bad Request..Content-Type: application/xml
  &lt;message xml:lang="en-US"&gt;Media type requires a '/' character.  &lt;/message&gt;
  </code></pre>
  
  <p>A similar issue is mentioned at <a href="http://social.msdn.microsoft.com/Forums/da/adodotnetdataservices/thread/e47ec51b-ea38-49f7-9814-d113907d4e3a" rel="nofollow noreferrer">Microsoft Social media types</a>. Anyone run into this and know how to resolve this?</p>
  
  <p>Any help would be much appreciated!</p>
  
  <p>Vanita</p>