我有一个sharepoint URL,其端点是.aspx页面,在浏览到网页后返回我的名字列表但是当我在我的代码中使用它时,它返回整个HTML,这有点难以解析该信息。 任何人都可以提出解决这个问题的好方法
编辑:
我在google上找到了以下代码
import java.io.FileInputStream;
import java.util.Properties;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.Credentials;
import org.apache.http.auth.NTCredentials;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.params.AuthPolicy;
import org.apache.http.impl.auth.SPNegoSchemeFactory;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.json.JSONObject;
import microsoft.exchange.webservices.data.ExchangeService;
import microsoft.exchange.webservices.data.ExchangeVersion;
public class SharPointClient {
public static void main(String[] args) {
try{
//Load Property
Properties prop = new Properties();
prop.load(new FileInputStream("config.properties"));
//Get exchange service object
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
String passWd = prop.getProperty("mailPwd");
String sharePointUser = prop.getProperty("sharePointUser");
String BaseUrl = "http://server/default.aspx";
DefaultHttpClient httpClient = new DefaultHttpClient();
httpClient.getAuthSchemes().register(AuthPolicy.SPNEGO, new SPNegoSchemeFactory());
/*Credentials useJaasCredentials = new Credentials() {
public String getPassword() { return null; }
public String getUserPrincipal() { return null; }
};
httpClient.getCredentialsProvider().setCredentials(
new AuthScope(null, -1, null),
useJaasCredentials
);*/
httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY,new NTCredentials(sharePointUser, passWd, "","mydomain"));
HttpUriRequest request = new HttpGet(BaseUrl);
request.addHeader("Accept", "application/json;odata=verbose");
HttpResponse response = httpClient.execute(request);
HttpEntity entity = response.getEntity();
String results = EntityUtils.toString(entity);
System.out.println(results);
}catch(Exception e){
e.printStackTrace();
}
}
}
这会将我的响应作为该响应的整个HTML返回,这非常难以解析,因此我尝试通过JSoupe
,但这对我来说似乎也没用。
答案 0 :(得分:0)
您需要使用sharepoint REST Service界面。我想你需要的是List接口实现。你能检查一下页面是否返回一个列表。否则你必须刮掉那个痛苦的HTML页面。
http://server_name/_vti_bin/Lists.asmx显示了处理列表和列表数据的方法。