发布到Siteminder login.fcc以使用java检索cookie
我的应用程序需要访问一些受SiteMinder保护的URL,因此需要SiteMinder代理提供的SMSession cookie 我想通过将我的登录凭据发布到Siteminder登录表单来获取SMSession cookie 我尝试了许多不同的方法来访问和发布所需的数据目标、smauthreason、smagentname、用户名和密码到login.fcc。 我可以像这样把它贴在邮递员/小提琴手上,然后取回一块饼干发布到Siteminder login.fcc以使用java检索cookie,java,authentication,login,siteminder,Java,Authentication,Login,Siteminder,我的应用程序需要访问一些受SiteMinder保护的URL,因此需要SiteMinder代理提供的SMSession cookie 我想通过将我的登录凭据发布到Siteminder登录表单来获取SMSession cookie 我尝试了许多不同的方法来访问和发布所需的数据目标、smauthreason、smagentname、用户名和密码到login.fcc。 我可以像这样把它贴在邮递员/小提琴手上,然后取回一块饼干 try { URL requestURL = new URL(
try {
URL requestURL = new URL("HTTPS_URL_TO_THE/login-captcha.fcc");
HttpsURLConnection conn = (HttpsURLConnection) requestURL.openConnection();
conn.setDoOutput(true);
//conn.setDoInput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("Host", "HOST_FROM_ABOVE");
conn.setRequestProperty("Connection", "keep-alive");
conn.setRequestProperty("Content-Length","" + createBody().getBytes().length);
conn.setRequestProperty("Cache-Control", "max-age=0");
conn.setRequestProperty("Origin", "ORIGIN_HOST_FROM_WHERE_POSTED");
conn.setRequestProperty("Upgrade-Insecure-Requests", "1");
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36");
conn.setRequestProperty("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8");
conn.setRequestProperty("DNT", "1");
conn.setRequestProperty("Referer", "REFERER_TAKEN_FROM_FIDDLER");
conn.setRequestProperty("Accept-Encoding", "gzip, deflate, br");
conn.setRequestProperty("Accept-Language", "de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7");
OutputStream os = conn.getOutputStream();
os.write(createBody().getBytes());
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String in;
while ((in = br.readLine()) != null){
System.out.println(in);
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
我将获得一个连接,并可以访问页面时,我提供了cookie之前。但在这一步中,我想检索cookie
车身数据100%正确。
上面示例中使用的标题并非都是必需的。这是我最后一次孤注一掷的发帖,与《费德勒》一模一样。但我不会得到登录或302HTTP重定向
为什么不起作用?有什么建议吗?我找到了解决问题的办法。事实上,我将不得不手动处理重定向。如果我自动执行重定向,则检索到的cookie不会随下一个请求一起发送。 在没有cookie的情况下发布到targetURL会自动重定向到登录页面
URL protectedURL = new URL(protectedURLString);
HttpsURLConnection conn = (HttpsURLConnection) protectedURL.openConnection();
conn.setInstanceFollowRedirects(false);
boolean redirect = false;
System.out.println("Request URL: " + protectedURL);
//Check for redirection
int status = conn.getResponseCode();
if(status != HttpURLConnection.HTTP_OK) {
if(status == HttpURLConnection.HTTP_MOVED_TEMP
|| status == HttpURLConnection.HTTP_MOVED_PERM
|| status == HttpURLConnection.HTTP_SEE_OTHER) {
redirect = true;
}
}
System.out.println("Response Code: " + status);
//If redirected
if(redirect) {
//get new redirect URL from Location header field
String newURL = conn.getHeaderField("Location");
URL tempURL = new URL(newURL);
String query = tempURL.getQuery();
//Read parameters from query
String [] params = query.split("&");
for (String param : params) {
String [] parts = param.split("=");
String key = parts[0].toLowerCase();
String value = "";
if(parts.length > 1)
value = parts[1];
updateVars(key, value);
}
}
postToLogin(this.URL_LOGIN);
这是我的解决方案中使用的一些代码。updateVarskey,value更新类变量。posttologinnis.URL\u LOGIN发布到包含使用类变量生成的主体的登录URL