lundi 23 février 2015

POST a file to Document library using java



How do I make a post request to a document library using java?


I'm using the lastest version on this library http://hc.apache.org/


This is my post request right now:


itemUrl looks like this: http://industrial-ex/sites/tifdemo/enovia/FILENAME.txt



public void addItem(String itemUrl, File file) throws IOException {
FileInputStream fileInputStream = new FileInputStream(file);
HttpEntity test = new InputStreamEntity(fileInputStream);
HttpPost request = new HttpPost(itemUrl);
System.out.println("ITEM URL: " + itemUrl);
request.addHeader("Content-Type", "application/json;odata=verbose");
request.setEntity(test);
CloseableHttpResponse response = httpClient.execute(target, request, context);
response.addHeader("Content-Type", "application/json;odata=verbose");
System.out.println("STATUS CODE POST: " + response.getStatusLine());

}


I'm getting a status code:



200 OK



but my document library is empty and nothing shows up.








0 commentaires:

Enregistrer un commentaire