title: post data using Sharepoint 2010 REST API using Java http client
body: <p>I am trying to post a SharePoint list item to a SharePoint 2010 list using Java client.
  I am able to read the SP list items using below code but I am not sure how to write to the SharePoint.
  For the post operation, I am getting http 401 error.
  Any guidance will be greatly appreciated.</p>
  
  <p>GET Operation: </p>
  
  <pre><code>String url = "https://organization.company.com/sites/Ateam/_vti_bin/ListData.svc/TableLoadInfo";        DefaultHttpClient client = new DefaultHttpClient();
  
          NTCredentials credentials = new NTCredentials(username, password, hostname, domain);
          AuthScope scope = new AuthScope(hostname, 443);
  
          SSLContext sslcontext = SSLContext.getInstance("TLS");
          sslcontext.init(null, new TrustManager[] { trustmanager }, null);
  
          SSLSocketFactory sf = new SSLSocketFactory(sslcontext,              SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
          Scheme https = new Scheme("https", 443, sf);
  
          client.getConnectionManager().getSchemeRegistry().register(https);
          client.getCredentialsProvider().setCredentials(scope, credentials);
  
          HttpGet request = new HttpGet(url);
          //request.addHeader("Accept", "application/xml");
          request.addHeader("Accept", "application/json;odata=verbose");
  
          HttpResponse response = client.execute(request);
  </code></pre>
  
  <p>POST Operation:</p>
  
  <p>String url = "<a href="https://organization.company.com/sites/Ateam/_vti_bin/ListData.svc/TableLoadInfo" rel="nofollow">https://organization.company.com/sites/Ateam/_vti_bin/ListData.svc/TableLoadInfo</a>";</p>
  
  <p>DefaultHttpClient client = new DefaultHttpClient();</p>
  
  <pre><code>        NTCredentials credentials = new NTCredentials(username, password, hostname, domain);
          AuthScope scope = new AuthScope(hostname, 443);
  
          SSLContext sslcontext = SSLContext.getInstance("TLS");
          sslcontext.init(null, new TrustManager[] { trustmanager }, null);
  
          SSLSocketFactory sf = new SSLSocketFactory(sslcontext, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
          Scheme https = new Scheme("https", 443, sf);
  
          client.getConnectionManager().getSchemeRegistry().register(https);
          client.getCredentialsProvider().setCredentials(scope, credentials);
  
          // POST a data
          HttpPost request = new HttpPost(url);
  
                      request.addHeader("Accept", "application/json;odata=verbose");
          request.addHeader("Content-type", "application/json;odata=verbose");
          // request.addHeader("X-RequestDigest", FormDigestValue);
          request.addHeader("X-HTTP-Method", "POST");
          request.addHeader("If-Match", "*");
  
          JSONStringer json = (JSONStringer) new JSONStringer().object().key("Table_Name").value("TableName 1")
                  .key("Load_Frequency").value("Weekly").key("Cycle").value("CURRENT").endObject();
  
  
          StringEntity se = new StringEntity(json.toString());
          request.setEntity(se);
  
                      HttpResponse response = client.execute(request);
  </code></pre>