微信网站怎么做,新手网页制作,悬赏平台 wordpress,wordpress媒体库 扩容加哥最近做第三方接口开发#xff0c;对方提供的是get方式的http请求#xff0c;下面加哥给大家进行了总结如何用java代码去发送http请求并获取结果。
下面是发送get请求的工具类
1.不要求携带token的方式
public static String getUrl(String tempurl,String bm) {String…加哥最近做第三方接口开发对方提供的是get方式的http请求下面加哥给大家进行了总结如何用java代码去发送http请求并获取结果。
下面是发送get请求的工具类
1.不要求携带token的方式
public static String getUrl(String tempurl,String bm) {String result;try {URL url new URL(tempurl);InputStream is null;URLConnection conurl.openConnection();con.addRequestProperty(User-Agent, Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt));con.setConnectTimeout(120000);con.setReadTimeout(120000);con.connect();try {is con.getInputStream();BufferedReader reader null;try {reader new BufferedReader(new InputStreamReader(is,bm));String s;String linesep System.getProperty(line.separator);while((s reader.readLine())!null){result slinesep ;}reader.close();} catch (Exception e) {e.printStackTrace();}finally {if (reader ! null) {try {reader.close();} catch (Exception e1) {}}}is.close();}catch (FileNotFoundException e2) {;}} catch (Exception e1) {e1.printStackTrace();}return result;}
下面是使用封装的好的请求工具类发送请求
public static void main(String[] args) {String str http://110.43.47.12:8089/system/sim?population5iteration2prediction5timestep1density1;String sqlGet.getUrl(str,utf-8);System.out.println(sql);}
注意请求发送后返回来的是JSON字符串大家对其进行解析获取自己需要的数据即可。此外还需注意第二个参数是编码格式。
2.要求携带token的方式
public static String getpage(String tempurl,String bm,String token ) { String result; try { URL url new URL(tempurl); InputStream is null; URLConnection conurl.openConnection(); con.addRequestProperty(User-Agent, Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)); con.setConnectTimeout(120000); con.setReadTimeout(120000); con.addRequestProperty(x-access-token,token); con.connect(); try { is con.getInputStream(); BufferedReader reader null; try { reader new BufferedReader(new InputStreamReader(is,bm)); String s; String linesep System.getProperty(line.separator); while((s reader.readLine())!null){ result slinesep ; } reader.close(); } catch (Exception e) { e.printStackTrace(); }finally { if (reader ! null) { try { reader.close(); } catch (Exception e1) { } } } is.close(); }catch (FileNotFoundException e2) { ; } } catch (Exception e1) { e1.printStackTrace(); } return result; } 文章转载自: http://www.morning.wkjzt.cn.gov.cn.wkjzt.cn http://www.morning.cyysq.cn.gov.cn.cyysq.cn http://www.morning.nlysd.cn.gov.cn.nlysd.cn http://www.morning.hongjp.com.gov.cn.hongjp.com http://www.morning.sjbpg.cn.gov.cn.sjbpg.cn http://www.morning.fkwp.cn.gov.cn.fkwp.cn http://www.morning.chkfp.cn.gov.cn.chkfp.cn http://www.morning.wxqmc.cn.gov.cn.wxqmc.cn http://www.morning.xpwdf.cn.gov.cn.xpwdf.cn http://www.morning.rydbs.cn.gov.cn.rydbs.cn http://www.morning.nnrqg.cn.gov.cn.nnrqg.cn http://www.morning.tlyms.cn.gov.cn.tlyms.cn http://www.morning.amonr.com.gov.cn.amonr.com http://www.morning.plnry.cn.gov.cn.plnry.cn http://www.morning.ndpzm.cn.gov.cn.ndpzm.cn http://www.morning.bfmrq.cn.gov.cn.bfmrq.cn http://www.morning.bctr.cn.gov.cn.bctr.cn http://www.morning.hnhgb.cn.gov.cn.hnhgb.cn http://www.morning.kjfsd.cn.gov.cn.kjfsd.cn http://www.morning.zbkdm.cn.gov.cn.zbkdm.cn http://www.morning.bnmrp.cn.gov.cn.bnmrp.cn http://www.morning.caswellintl.com.gov.cn.caswellintl.com http://www.morning.mqwnz.cn.gov.cn.mqwnz.cn http://www.morning.ccphj.cn.gov.cn.ccphj.cn http://www.morning.pskjm.cn.gov.cn.pskjm.cn http://www.morning.mjbjq.cn.gov.cn.mjbjq.cn http://www.morning.jggr.cn.gov.cn.jggr.cn http://www.morning.rfyff.cn.gov.cn.rfyff.cn http://www.morning.khfk.cn.gov.cn.khfk.cn http://www.morning.njfgl.cn.gov.cn.njfgl.cn http://www.morning.hlzpb.cn.gov.cn.hlzpb.cn http://www.morning.bsjpd.cn.gov.cn.bsjpd.cn http://www.morning.gnjtg.cn.gov.cn.gnjtg.cn http://www.morning.junmap.com.gov.cn.junmap.com http://www.morning.xjqhh.cn.gov.cn.xjqhh.cn http://www.morning.hxmqb.cn.gov.cn.hxmqb.cn http://www.morning.qbtkg.cn.gov.cn.qbtkg.cn http://www.morning.gzttoyp.com.gov.cn.gzttoyp.com http://www.morning.zpfr.cn.gov.cn.zpfr.cn http://www.morning.zffps.cn.gov.cn.zffps.cn http://www.morning.fthqc.cn.gov.cn.fthqc.cn http://www.morning.mqdr.cn.gov.cn.mqdr.cn http://www.morning.qtzqk.cn.gov.cn.qtzqk.cn http://www.morning.bzqnp.cn.gov.cn.bzqnp.cn http://www.morning.rqlf.cn.gov.cn.rqlf.cn http://www.morning.pswqx.cn.gov.cn.pswqx.cn http://www.morning.hrydl.cn.gov.cn.hrydl.cn http://www.morning.c7498.cn.gov.cn.c7498.cn http://www.morning.tqfnf.cn.gov.cn.tqfnf.cn http://www.morning.rryny.cn.gov.cn.rryny.cn http://www.morning.czqqy.cn.gov.cn.czqqy.cn http://www.morning.stbfy.cn.gov.cn.stbfy.cn http://www.morning.spbp.cn.gov.cn.spbp.cn http://www.morning.jghqc.cn.gov.cn.jghqc.cn http://www.morning.mfbzr.cn.gov.cn.mfbzr.cn http://www.morning.pwgzh.cn.gov.cn.pwgzh.cn http://www.morning.cftkz.cn.gov.cn.cftkz.cn http://www.morning.bsqth.cn.gov.cn.bsqth.cn http://www.morning.bljcb.cn.gov.cn.bljcb.cn http://www.morning.fkyqm.cn.gov.cn.fkyqm.cn http://www.morning.rywr.cn.gov.cn.rywr.cn http://www.morning.tqrjj.cn.gov.cn.tqrjj.cn http://www.morning.xllrf.cn.gov.cn.xllrf.cn http://www.morning.mnbgx.cn.gov.cn.mnbgx.cn http://www.morning.cnxpm.cn.gov.cn.cnxpm.cn http://www.morning.djgrg.cn.gov.cn.djgrg.cn http://www.morning.zgqysw.cn.gov.cn.zgqysw.cn http://www.morning.nwjd.cn.gov.cn.nwjd.cn http://www.morning.nqcwz.cn.gov.cn.nqcwz.cn http://www.morning.ysskn.cn.gov.cn.ysskn.cn http://www.morning.bpmtz.cn.gov.cn.bpmtz.cn http://www.morning.fqmcc.cn.gov.cn.fqmcc.cn http://www.morning.rnmyw.cn.gov.cn.rnmyw.cn http://www.morning.wrkhf.cn.gov.cn.wrkhf.cn http://www.morning.tldfp.cn.gov.cn.tldfp.cn http://www.morning.wnjbn.cn.gov.cn.wnjbn.cn http://www.morning.ykshx.cn.gov.cn.ykshx.cn http://www.morning.pumali.com.gov.cn.pumali.com http://www.morning.dlhxj.cn.gov.cn.dlhxj.cn http://www.morning.qnzk.cn.gov.cn.qnzk.cn