根据我的经验,我认为您可以尝试直接按照您所引用的文章一步一步地使用Apache HttpClient来构造请求。
例如,下面的代码使用HttpClient
xml 正文执行 post 请求以获取安全令牌。
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost("https://login.microsoftonline.com/extSTS.srf");
String xmlBody = "...";
InputStreamEntity reqEntity = new InputStreamEntity(
new ByteArrayInputStream(xmlBody.getBytes(), -1, ContentType.APPLICATION_OCTET_STREAM);
reqEntity.setChunked(true);
httpPost.addHeader("Accept", "application/json; odata=verbose")
httpPost.setEntity(reqEntity);
CloseableHttpResponse response = httpclient.execute(httppost);
String respXmlBody = EntityUtils.toString(response.getEntity());
//Parse the respXmlBody and extract the security token
您可以尝试按照上面的代码通过使用 url 的安全令牌正文执行发布请求来获取包含访问令牌的响应https://yourdomain.sharepoint.com/_forms/default.aspx?wa=wsignin1.0
,并使用该代码Header[] hs = response.getHeaders("Set-Cookie");
获取Set-Cookie
标头数组作为访问令牌。
然后使用它们设置两个标头Cookie
以获取请求摘要令牌,并解析响应正文以提取FormDigestValue
作为请求摘要令牌。