0

我正在尝试使用 HttpURLConnection 为 j_spring_security_check 制作动态动态帖子。这是我的代码:

String urlToGo="http://localhost:8080/projectRef/j_spring_security_check";
String urlParameters ="j_username="+URLEncoder.encode(user.getEmailPro(), "UTF-8")+"&j_password="+URLEncoder.encode(user.getMdpUser(), "UTF-8");
URL url = new URL(urlToGo); 
conn.setUseCaches (true);
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setRequestMethod("POST");
conn.setInstanceFollowRedirects(true);  //you still need to handle redirect manully.
HttpURLConnection.setFollowRedirects(true);
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
DataOutputStream wr = new DataOutputStream(conn.getOutputStream ());
wr.writeBytes(urlParameters);
wr.flush();
wr.close();
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line = "";
while((line=in.readLine())!=null) {
      System.out.println(line);
}
in.close();

但是当我执行它时,我得到的只是登录页面的代码。并且身份验证不处理。有人可以帮我吗?

4

0 回答 0