当您使用 HttpsURLConnection 并返回代码 302 时如何获取 html
我想通过登录表单进行连接。我发送连接信息。问题是,在识别之后,网站会进行重定向,当我使用方法connection.getResponseCode()测试我的对象HttpsURLConnection时,我有代码302(HTTP状态代码302:临时重定向。)
- 如何使用我的对象连接来获取html重定向后的代码?
连接后如何使用我的连接在所有站点中导航?
HttpsURLConnection 连接 = (HttpsURLConnection) url.openConnection(); 连接.setDoOutput(true); 连接.setRequestMethod("POST"); request.write("登录名=ll&密码=pp"); request.flush(); 请求.close(); 字符串行=“”; InputStreamReader isr = new InputStreamReader(connection.getInputStream()); //....获取字符串
谢谢你的回答:)
I want to connect at login form. I send informations for connections. The problem, after identification, the website do a redirection and when i test my Object HttpsURLConnection with method connection.getResponseCode(), i have code 302 (HTTP Status-Code 302: Temporary Redirect.)
- how can use my object connection for get html code after redirection?
How can use my connetion for navigate in all site after connection?
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection(); connection.setDoOutput(true); connection.setRequestMethod("POST"); request.write("login=ll&password=pp"); request.flush(); request.close(); String line = ""; InputStreamReader isr = new InputStreamReader(connection.getInputStream()); //.... get string
thx for your answer :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以读取位置标头以查看您被重定向到的位置
,然后打开到该 URL 的新连接。
您很可能从 HTTPS(登录)重定向到 HTTP(登录后)。有关为什么 HttpURLConnection 的信息,请参阅另一个问题的此答案在这种情况下不会自动遵循重定向。
You can read the location header to see where you've been redirected to
and then open a new connection to that URL.
You are most likely being redirected from HTTPS (login) to HTTP (post login). See this answer to another question for information on why HttpURLConnection is not automatically following the redirect in this case.