1

I am Using apache Http Client for connecting sharepoint using rest api.

code snippet is as below:

HttpClient client = HttpClientBuilder.create().build();
String baseurl = messages.getString("baseurl");
HttpPost post = new HttpPost(baseurl + "_api/contextinfo");
post.setHeader("Accept", "application/json; odata=verbose");
post.setHeader("content-type", "application/json; odata=verbose");
//post.setHeader("DataServiceVersion", "3.0");  
//post.setHeader("Content-Length", "2");

post.addHeader("Cookie", cookie);
System.out.println("post===>"+cookie);
System.out.println("post===>"+post);

HttpResponse response = client.execute(post);
System.out.println("response===>"+response.toString());
int httpStatus = 0;
if (null != response && null != response.getStatusLine()) {
     httpStatus = response.getStatusLine().getStatusCode();
}

I am getting an error. Please help me.

  • check if the variable baseurl contains a "/" in the end or not? I guess you are forgetting to put a forward slash in the beginning of /_api/contextinfo – Ankit Katiyar Feb 6 at 8:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.