使用HttpGet 发送 json格式的参数
来源:互联网 发布:网络新技术有哪些方面 编辑:程序博客网 时间:2024/05/16 16:58
由于工作需要使用java实现http客户端发送get请求,且参数值为json格式,几经周折得以实现,现在记录分享如下:
hashMap 参数实例:
Map<String, Object> indata = new HashMap(); indata.put("berthstatus", 1); indata.put("berthcode", "22333"); indata.put("parkcode", "6688"); Map<String, Object> param = new HashMap(); param.put("indata",indata);
具体实现函数:
protected void requestService(Map<String,Object> reqmap) throws Exception { JSONObject obj = new JSONObject(reqmap); String r = URLEncoder.encode(obj.toString(), "UTF-8"); String reqUrl = "http://192.168.17.35:8888/getParkInfo?jsonString=" + r; System.out.println("请求参数:" + reqUrl); CloseableHttpResponse response = null; CloseableHttpClient client = null; String res = null; HttpGet httpGet = new HttpGet(reqUrl); System.out.println("executing request" + httpGet.getRequestLine()); try { client = HttpClients.createDefault(); response = client.execute(httpGet); if (response.getStatusLine().getStatusCode() == 200) { String result = EntityUtils.toString(response.getEntity()); System.out.println("executing result---连接正常" + result); } else { System.out.println("executing result---服务器连接异常"); } } catch (Exception e) { System.out.println("Exception================" + e.toString()); } finally { if (response != null) { response.close(); } if (client != null) { client.close(); } } }
阅读全文
0 0
- 使用HttpGet 发送 json格式的参数
- HTTPPOST 发送JSON格式参数
- asynchttpclient的post方法发送json格式参数和表单格式参数
- asynchttpclient的post方法发送json格式参数和表单格式参数
- 传入json格式的参数
- WebApi 的 HttpGet 和 HttpPost 传递多个参数对象的Json和Dynamic方法
- JS获取url参数、JS发送json格式的POST请求
- HttpClient使用HttpGet进行json数据传输
- HttpClient使用HttpGet进行json数据传输
- java_HttpClient使用HttpGet进行json数据传输
- python使用post方式发送json参数
- ExtJS发送POST请求 参数格式为JSON
- RestTemplate 发送json格式的http请求
- jquery 发送 json 格式的两个方法
- postman发送json格式的post请求
- HttpClient--HttpGet的使用样式
- HttpClient--HttpGet的使用样式
- Android的httpGet方法的参数字符串
- 2017年8月
- jquery实现日历选择功能
- 测试用例设计要点
- PAT 1018. public bike management (30)
- UVA442 Matrix Chain Multiplication【DP】
- 使用HttpGet 发送 json格式的参数
- logback配置---Spring集成logback
- 欢迎使用CSDN-markdown编辑器
- Android shape 的详解及使用
- 二维数组中的查找
- 单例模式和静态方法的比较
- VMware中ubuntu磁盘扩展
- Android业务组件化之现状分析与探讨
- Kotlin类和对象(一)——类与继承