HttpInvoker GET/POST方式
阅读原文时间:2023年07月16日阅读:2

1、GET方式

HttpGet httpGet = new HttpGet("http://localhost:8080/randomCode/getSouthUuid");
String sourceId = "100001";
String appkey = "34";
List arrayList = new ArrayList();
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 arrayList = new ArrayList();
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();

手机扫一扫

移动阅读更方便

阿里云服务器
腾讯云服务器
七牛云服务器

你可能感兴趣的文章