gpt4 book ai didi

java - 如何使用java模拟登录

转载 作者:行者123 更新时间:2023-11-30 07:20:39 24 4
gpt4 key购买 nike

我想使用httpurlconnection类来模拟登录网站。我试着捕获数据包以获取请求 header ,并将其全部放入我的程序中。但是这段代码无法从服务器获取cookie。

    String username = "。。。。。。;
String password = ".。。。。";
String param = "username="+username+"&pwd="+password+"&usertype=xuesheng&Submit=+%B5%C7%C2%BD+";
HttpURLConnection connection = (HttpURLConnection)urlx.openConnection();
connection.setRequestProperty("Host","jwc.ecjtu.jx.cn:8080");
connection.setRequestProperty("Connection","keep-alive");
connection.setRequestProperty("Content-Length","74");
connection.setRequestProperty("Cache-Control","max-age=0");
connection.setRequestProperty("Content-Length","http://jwc.ecjtu.jx.cn:8080");
connection.setRequestProperty("Upgrade-Insecure-Requests","1");
connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.63 Safari/537.36");
connection.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
connection.setRequestProperty("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
connection.setRequestProperty("DNT","1");
connection.setRequestProperty("Referer","http://jwc.ecjtu.jx.cn:8080/jwcmis/assess/");
connection.setRequestProperty("Accept-Encoding","gzip, deflate");
connection.setRequestProperty("Accept-Language","zh-CN,zh;q=0.8");
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setRequestMethod("POST");

这是我发送到服务器的关键代码。我该怎么做才能模拟登录成功?我还应该添加什么代码?

最佳答案

我认为你应该阅读 CookieHandler

有java模拟登录解决方案示例http://www.mkyong.com/java/how-to-automate-login-a-website-java-example/

关于java - 如何使用java模拟登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37631099/

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