1. Open chrome and its developer tool
2. Conduct the login operation in chrome, record the network intercourse.
3. Analyze the HTTP Request and HTTP Response
Request Headers
POST /member/xlogin.php HTTP/1.1
Host: xxx.com
Connection: keep-alive
Content-Length: 43
Pragma: no-cache
Cache-Control: no-cache
Origin: http://xxx.com
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.101 Safari/537.36
Content-type: application/x-www-form-urlencoded
Accept: */*
Referer: http://xxx.com/member/
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.8
Cookie: _ga=GA1.2.1137125247.1417626456
Form Data
username=cccc000&passwd=123456&lang=zh-cn
Beware the content-type and the form data format. Note how to work it out by jsoup.
public static void login() {
try {
String url = "http://xxx.com/member/xlogin.php";
Map<String, String> formData = new HashMap<>();
formData.put("username", "cccc000");
formData.put("passwd", "123456");
formData.put("lang", "zh-cn");
Document doc = Jsoup
.connect(url)
.followRedirects(true)
.referrer("http://xxx.com/member/")
.userAgent(
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.101 Safari/537.36")
.data(formData).post();
System.out.println(doc.html());
} catch (IOException e) {
e.printStackTrace();
}
}