我正在努力让 java 通过 HTTPS 提交 POST 请求
使用的代码在这里
try{ Response res = Jsoup.connect(LOGIN_URL) .data("username", "blah", "password", "blah") .method(Method.POST) .userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64; rv:19.0) Gecko/20100101 Firefox/19.0") .header("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8") .execute(); System.out.println(res.body()); System.out.println("Code " +res.statusCode()); } catch (Exception e){ System.out.println(e.getMessage()); }
还有这个
Document doc = Jsoup.connect(LOGIN_URL) .data("username", "blah") .data("password", "blah") .userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64; rv:19.0) Gecko/20100101 Firefox/19.0") .header("Content-type", "application/x-www-form-urlencoded") .method(Method.POST) .timeout(3000) .post();
其中 LOGIN_URL = https://xxx.com/Login?val=login
当通过 HTTP 使用时,它似乎可以工作,HTTPS 则不行,但不会抛出任何异常
如何通过 HTTPS 发送
编辑:
当服务器通过 HTTPS 获取 POST 时似乎涉及 302 重定向(这不会通过 http 发生)我如何使用 jsoup 将 302 发送的 cookie 存储到下一页?
最佳答案
这是我的代码:
URL form = new URL(Your_url);
connection1 = (HttpURLConnection)form.openConnection();
connection1.setRequestProperty("Cookie", your_cookie);
connection1.setReadTimeout(10000);
StringBuilder whole = new StringBuilder();
BufferedReader in = new BufferedReader(
new InputStreamReader(new BufferedInputStream(connection1.getInputStream())));
String inputLine;
while ((inputLine = in.readLine()) != null)
whole.append(inputLine);
in.close();
Document doc = Jsoup.parse(whole.toString());
String title = doc.title();
我已使用此代码获取新页面的标题。
关于java - jsoup 发布 Java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15210390/