JSOUP 支持在请求的时候,传入URL
对象,而后设置编码。以下方式才是正解,设置编码为GBK
。缓存
doc = Jsoup.parse(new URL(url).openStream(), "GBK", url);
若是对方是UTF-8
,那就设置为UTF-8
post
RL url = new URL("https://sms.reyo.cn"); HttpURLConnection connection = (HttpURLConnection)url.openConnection(); //默认就是Get,能够采用post,大小写都行,由于源码里都toUpperCase了。 connection.setRequestMethod("GET"); //是否容许缓存,默认true。 connection.setUseCaches(Boolean.FALSE); //是否开启输出输入,若是是post使用true。默认是false //connection.setDoOutput(Boolean.TRUE); //connection.setDoInput(Boolean.TRUE); //设置请求头信息 connection.addRequestProperty("Connection", "close"); //设置链接主机超时(单位:毫秒) connection.setConnectTimeout(8000); //设置从主机读取数据超时(单位:毫秒) connection.setReadTimeout(8000); //设置Cookie connection.addRequestProperty("Cookie","你的Cookies" ); //开始请求 Document doc = Jsoup.parse(connection.getInputStream(), "GBK", "https://sms.reyo.cn"); //TODO ---