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();
轉載于:https://www.cnblogs.com/wangxiaoheng/p/7299424.html
總結
以上是生活随笔為你收集整理的HttpInvoker GET/POST方式的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 小爬简单模式
- 下一篇: 编译程序提示配置PKG_CONFIG_P