0
帮助我与jsoup登录,我必须登录,然后从登录页面重定向到另一个页面与保存的会话。java.io.IOException:403错误加载URL jsoup登录
public void parseXhtml() throws IOException{
String sessionID=null;
Map<String, String> cookies = new HashMap<String, String>();
cookies.put("login", "login");
cookies.put("password", "password");
Connection conn=Jsoup.connect("http://localhost:8080/dir/login.xhtml");
Connection.Response res = Jsoup
.connect("http://localhost:8080/dir/login.xhtml")
.data(cookies)
.execute();
res = Jsoup.connect("http://localhost:8080/dir/dir/index.xhtml")
.cookie("JSESSIONID", res.cookies().get("JSESSIONID"))
.method(Method.GET)
.userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36")
.execute();
Document doc = res.parse();
System.out.println(doc.html());
sessionID = res.cookie("JSESSIONID");
Document docu = Jsoup.connect("http://localhost:8080/dir/dir/index.xhtml")
.userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36")
.cookie("JSESSIONID", res.cookies().get("JSESSIONID"))
.method(Connection.Method.GET)
.get();
它抛出下面的异常
产生java.io.IOException:403错误加载URL http://localhost:8080/dir/dir/index.xhtml
如果我做像[Sending POST request with username and password and save session cookie它抛出同样的异常。
@BalusC,如果我做喜欢http://stackoverflow.com/questions/7206133/sending-post -request-and-save-cookies/7206268#7206268存在相同的错误。 – DoctorDo
如果您的html表单不同,您需要更改数据。这适用于duplciate:http://stackoverflow.com/q/12175763 – BalusC
@BalusC,我必须以编程方式登录并获取sessionId.How我可以得到所需页面的内容?请帮助 – DoctorDo