我点击了其他网址
https://db2adminpc1:9443/rest/bpm/wle/v1/search/query?organization=byInstance&run=true&shared=false&filterByCurrentUser=true
使用 HttpURLConnection 类,我在输入流中获取 SJON 数据。
但是在我的要求中,当我点击 URL 时,它应该存储某种令牌或 cookie 以在我在 chrome 浏览器中打开 URL 时对 URL 进行身份验证。您可以在下面找到代码:
byte[] encodedBytes = Base64.getEncoder().encode(Data.getBytes());
URL url = new URL(
"https://db2adminpc1:9443/rest/bpm/wle/v1/search/query?organization=byInstance&run=true&shared=false&filterByCurrentUser=true");
connection = (HttpURLConnection) url.openConnection();
String encoding = new String(encodedBytes);// "cGNhZG1pbjpwY2FkbWlu";
connection.setRequestMethod("POST");
connection.setDoOutput(true);
connection.setRequestProperty("Authorization", "Basic " + encoding);
connection.getRequestProperty("Set-Cookie");
System.out.println("Session iD " + connection.getHeaderField("Set-Cookie"));
System.out.println("Session iD " + connection.getHeaderField("Set-Cookie"));
if (connection.getResponseCode() == 200) {
InputStream content = (InputStream) connection.getInputStream();
BufferedReader in = new BufferedReader(new InputStreamReader(content));
while ((line = in.readLine()) != null) {
// System.out.println(line);
sb.append(line);
}
content.close();
} else {
sb.append("\"Username And Password Does Not Match!!!\"");
}
}
Update I am able read LTPatoken2 but dont know how to put or store in localhost cookie and authenticate the URL