gpt4 book ai didi

java - 为什么我的 POST 请求 (HTTPS) 请求失败?

转载 作者:太空宇宙 更新时间:2023-11-04 07:20:26 24 4
gpt4 key购买 nike

我正在尝试为我的学校 WiFi 登录系统制作一个自动登录程序。我需要对身份验证 URL ( https://ccahack.bergen.org/auth/perfigo_validate.jsp ) 执行 POST 请求并提交一些参数。如果我将 HTTPS 更改为 HTTP 并执行 POST 请求,它只会将我重定向回登录论坛。因此,我必须 POST 到 HTTPS,但问题是我收到 SSL 套接字错误,这是我的代码:

public boolean signIn() throws Exception{
//System.setProperty("http.agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.29 Safari/537.36");
String httpsURL = "https://ccahack.bergen.org/auth/perfigo_validate.jsp";
String username = "username";
String password = "password";
StringBuilder q = new StringBuilder();
q.append("reqFrom="+URLEncoder.encode("perfigo_simple_login.jsp","UTF-8"));
q.append("&uri="+ URLEncoder.encode("https://ccahack.bergen.org/","UTF-8"));
q.append("&cm=" + URLEncoder.encode("ws32vklm", "UTF-8"));
q.append("&userip="+URLEncoder.encode("IP_ADDRESS HERE","UTF-8"));
q.append("&os=" +URLEncoder.encode("MAC_OSX","UTF-8"));
q.append("&index="+URLEncoder.encode("4","UTF-8"));
q.append("&username="+URLEncoder.encode(username,"UTF-8"));
q.append("&password="+URLEncoder.encode(password,"UTF-8"));
q.append("&provider="+URLEncoder.encode("BCA","UTF-8"));
q.append("&login_submt="+URLEncoder.encode("Continue","UTF8"));
String query = q.toString();
URL myurl = new URL(httpsURL);
HttpsURLConnection con = (HttpsURLConnection)myurl.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Content-length", String.valueOf(query.length()));
con.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
con.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0;Windows98;DigExt)");
con.setDoOutput(true);
con.setDoInput(true);

DataOutputStream output = new DataOutputStream(con.getOutputStream());
//error here

output.writeBytes(query);

output.close();

DataInputStream input = new DataInputStream( con.getInputStream() );



for( int c = input.read(); c != -1; c = input.read() )
System.out.print( (char)c );
input.close();

System.out.println("Resp Code:"+con.getResponseCode());
System.out.println("Resp Message:"+ con.getResponseMessage());
return false;
}

最佳答案

根据您在评论中发布的异常(exception)情况,您需要确保该网站的证书位于您的信任库中。 (假设您信任它。)

这是我不久前写过的东西:

http://springinpractice.com/2012/04/29/fixing-pkix-path-building-issues-when-using-javamail-and-smtp/

在本例中,我正在执行 SMTP(您正在执行 HTTP),因此您需要对此进行调整。

关于java - 为什么我的 POST 请求 (HTTPS) 请求失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19414892/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com