700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > java http请求 HttpURLConnection 302 重定向 -08-03

java http请求 HttpURLConnection 302 重定向 -08-03

时间:2018-12-19 08:32:49

相关推荐

java http请求 HttpURLConnection 302 重定向 -08-03

HttpURLConnection con = null;try {String url ="http://.。。。.com";// 获取文件流con = (HttpURLConnection) new URL(url).openConnection();con.setConnectTimeout(15000);con.setReadTimeout(15000);con.setInstanceFollowRedirects(false);if (con.getResponseCode() == 302) {//如果会重定向,保存302重定向地址,以及Cookies,然后重新发送请求(模拟请求)String location = con.getHeaderField("Location");con.disconnect();url = location;con = (HttpURLConnection) new URL(url).openConnection();con.setConnectTimeout(15000);con.setReadTimeout(15000);}}catch (IOException e) {}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。