开发者

How to login to a webpage and get its html code with Java, when it uses post method for logging in?

开发者 https://www.devze.com 2022-12-22 05:33 出处:网络
I created an application tha开发者_如何学Got parses content of secured areas of one webpage after account information input. It used GET method for loging in, so it was quite simple, I just used URL t

I created an application tha开发者_如何学Got parses content of secured areas of one webpage after account information input. It used GET method for loging in, so it was quite simple, I just used URL to log in. Now it was changed to POST method and I wonder how to log in to that site? The login form uses 2 input tags of type text with names 'login' and 'pass'.


Are you using something like apache commons http. You can use post method.


Have you tried setting the request method?

HttpURLConnection conn = new HttpURLConnection(url);
conn.setRequestMethod("POST");
OutputStream os = conn.getOutputStream();
os.write(...);
Object content = conn.getContent();
0

精彩评论

暂无评论...
验证码 换一张
取 消