• 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();

  • 相关阅读:
    队列(queue)、优先队列(priority_queue)、双端队列(deque)
    20150720工作总结
    Spring使用远程服务之Hessian
    iBaits中SqlMapClientTemplate的使用
    java中常见的异常类
    java笔试面试中的坑
    java面试中常用的排序算法
    IBatis和Hibernate区别
    单例和多线程
    ThreadLocal
  • 原文地址:https://www.cnblogs.com/wangxiaoheng/p/7299424.html
Copyright © 2020-2023  润新知