<form action="http://example.com/login" method="post"> <input type="text" name="username" /> <input type="password" name="password" /> <input type="submit" name="login" value="Login" /></form>
您可以发布它并获取cookie,如下所示:
Response response = Jsoup.connect("http://example.com/login") .method(Method.POST) .data("username", username) .data("password", password) .data("login", "Login") .execute();Map<String, String> cookies = response.cookies();document document = response.parse(); // If necessary.// ...
您可以按以下要求将cookie传递回去:
document document = Jsoup.connect("http://example.com/user") .cookies(cookies) .get();// ...
或者,如果您知道单个cookie的名称,则:
document document = Jsoup.connect("http://example.com/user") .cookie("SESSIONID", cookies.get("SESSIONID")) .get();// ...
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)