HttpInvoker GET/POST方式
1、GET方式
HttpGet httpGet = new HttpGet("http://localhost:8080/randomCode/getSouthUuid");
String sourceId = "100001";
String appkey = "34";
List<NameValuePair> arrayList = new ArrayList<NameValuePair>();
arrayList.add(new BasicNameValuePair("clientId", sourceId));
arrayList.add(new BasicNameValuePair("appkey", appkey));
// 设置参数
String string = EntityUtils.toString(new UrlEncodedFormEntity(arrayList, "utf-8"));
httpGet.setURI(new URI(httpGet.getURI().toString() + "?" + string));
String str = httpInvoker.invoke(httpGet, HttpInvoker.STRING_ENTITY_HANDLER);
2、POST方式
HttpPost post = new HttpPost(url);
logger.debug("testpath --------->"+TESTPATH)
// 创建参数列表
List<NameValuePair> arrayList = new ArrayList<NameValuePair>();
arrayList.add(new BasicNameValuePair("code", "xxx"));
arrayList.add(new BasicNameValuePair("redirect_uri", "xxx"));
arrayList.add(new BasicNameValuePair("grant_type", "xxx"));
// url格式编码
UrlEncodedFormEntity uefEntity = new UrlEncodedFormEntity(arrayList, "UTF-8");
post.setEntity(uefEntity);
String str = httpInvoker.invoke(post, HttpInvoker.STRING_ENTITY_HANDLER);
JSONObject json = JSONObject.parseObject(str);
String values = json.get("xxx").toString();
最新文章
- UWP开发必备:常用数据列表控件汇总比较
- 鸟哥linux私房菜基础篇
- CSS盒模型
- JSP工作原理
- 状态模式 java &;&; php
- sp_executesql的执行计划会被重用(转载)
- Centos 6.5使用Bumblebee关闭N卡,冷却你的电脑
- 【安全组网】思科IOS设备基础应用
- Linux中与DNS相关的内容
- JMeter对Oracle数据库进行压力测试
- [TypeScript] Using Lodash in TypeScript with Typings and SystemJS
- BZOJ3564 信号增幅仪
- sublime设置sublimeREPL-python-run current file 快捷键
- Django 系列博客(八)
- python之线程(threading)
- 牛客网NOIP赛前集训营-提高组(第一场)B 数数字
- zabbix_windowsagent_cpu
- Excel中的基本概念
- Java调用.NET webservice方法的几种方式
- vue-cli环境搭建初探!