如何使用java模拟登录
我想使用httpurlconnection类来模拟登录网站。我试着 捕获数据包以获取请求头,我将其全部放在我的程序中。但此代码无法从服务器获取cookie如何使用java模拟登录,java,web,httpurlconnection,Java,Web,Httpurlconnection,我想使用httpurlconnection类来模拟登录网站。我试着 捕获数据包以获取请求头,我将其全部放在我的程序中。但此代码无法从服务器获取cookie String username = "。。。。。。; String password = ".。。。。"; String param = "username="+username+"&pwd="+password+"&usertype=xuesheng&Submit=+%B5%C7%C2%BD+
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");
这是我发送到服务器的关键代码。
我应该怎么做才能成功模拟登录?我还应该添加哪些代码?我认为您应该阅读
有一个java模拟登录解决方案的例子,我没有得到cookie的原因是我发布的网站将重定向链接,我没有设置setInstanceFollowRedirects(false)。我得到了错误的回答。所以我没有得到饼干对不起,这些天我在学校做作业。。。我的问题是,我提交的内容与浏览器的内容相同,但服务器并没有给我与浏览器的接收内容相同的响应