Java_HttpRequest方法
来源:互联网 发布:linux 调试动态库 编辑:程序博客网 时间:2024/06/07 09:58
/** * http调用 * * @param httpUrl :请求接口 * @param httpArg :参数 * @return 返回结果 */ public static String httpRequest(String httpUrl, String httpArg) { BufferedReader reader = null; String result = null; StringBuffer sbf = new StringBuffer(); httpUrl = httpUrl + "?" + httpArg; try { URL url = new URL(httpUrl); HttpURLConnection connection = (HttpURLConnection) url .openConnection(); connection.setConnectTimeout(3000);//超时时间,单位毫秒,3000是3秒 connection.setReadTimeout(3000); connection.setRequestMethod("GET"); // 填入apikey到HTTP header(百度接口) //connection.setRequestProperty("apikey", "11111"); connection.connect(); InputStream is = connection.getInputStream(); reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));//UTF-8 String strRead = null; while ((strRead = reader.readLine()) != null) { sbf.append(strRead); sbf.append("\r\n"); } reader.close(); result = sbf.toString(); } catch (Exception e) { e.printStackTrace(); } return result; }
阅读全文
0 0
- Java_HttpRequest方法
- 方法
- 方法
- 方法
- 方法
- 方法
- 方法
- 方法
- 方法
- 方法
- 方法
- 方法
- 方法
- 方法
- 方法
- 方法
- 方法
- 方法
- HTML5视频直播及H5直播扫盲
- JavaScript中的函数参数传递
- LeetCode 135. Candy--贪心算法
- 数据结构之单链表——C++模板类实现
- python 中 包的下载地址
- Java_HttpRequest方法
- HashSet HashTable HashMap的区别 及其Java集合介绍
- 匿名类里的参数引用
- javascript对象 以及对象属性深入学习
- C 之 读取和复制文件
- angular依赖注入:angular 依赖注入原理
- python学习(二)
- android NDK简介
- mongo学习笔记(三)-分片