我无法使用 JSoup 进行身份验证,但我设法解决了问题。我所做的是实现org.apache.commons.httpclient.HttpClient和org.apache.commons.httpclient.methods.GetMethod来连接和获取 DataInputStreamReader。DataInputStreamReader 将被传递给 JSoup,因此我们可以使用 JSoup 来解析 xml/html。请看下面的代码:
// codes
GetMethod method = new GetMethod(url);
// passing the credentials
HttpClient httpClient = new HttpClient();
httpClient.getState().setCredentials(org.apache.commons.httpclient.auth.AuthScope.ANY, new org.apache.commons.httpclient.NTCredentials(username,pass,url,domain));
Document doc = null; // org.jsoup.nodes.Document
if( http.executeMethod(method)==200){
doc = Jsoup.parse(new DataInputStream(method.getResponseBodyAsStream()), "UTF-8", url);
}
// codes