我需要在Java EE项目(Spring MVC)中上载Sharepoint Foundation 2010上的文档。我使用HttpClient与Sharepoint 2010 rest API进行交互,一切运行良好,但我有两个问题:
我的上传:
DefaultHttpClient httpClient = new DefaultHttpClient();
NTCredentials credentials = new NTCredentials(this.username, this.password, "", "");
httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, credentials);
String url = "[url to library api - ..../ListData.svc/library]";
String slug = "[url to document]";
HttpPost post = new HttpPost(url);
post.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, false);
post.setHeader("Content-Type", "multipart/form-data");
post.setHeader("Accept", "application/json; charset=utf-8; odata=verbose");
post.setHeader("Slug", slug);
MultipartEntity multipartContent = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
multipartContent.addPart(file.getName(), new FileBody(file));
post.setEntity(multipartContent);
HttpResponse response = httpClient.execute(post);
我的元数据更新:
DefaultHttpClient httpClient = new DefaultHttpClient();
NTCredentials credentials = new NTCredentials(this.username, this.password, "", "");
httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, credentials);
String url = "[url to document API - ....ListData.svc/library(ID)]";
HttpPost post = new HttpPost(url);
post.setHeader("Content-Type", "application/json");
post.setHeader("Accept", "application/json; charset=utf-8; odata=verbose");
post.setHeader("X-HTTP-Method", "MERGE");
post.setHeader("If-Match", etag);
post.setEntity(new StringEntity("[JSON update metadata]", ContentType.APPLICATION_JSON));
HttpResponse response = httpClient.execute(post);