• http调接口


    private static String doGetResult(String urlStr, Map<String, String> params)
    throws Exception {
    System.out.println(urlStr);
    PostMethod postMethod = new PostMethod(urlStr);
    try {
    postMethod.addParameter("info",
    URLEncoder.encode(Map2JSON(params), UTF8));
    HttpClient client = new HttpClient();
    postMethod.getParams().setParameter(
    HttpMethodParams.HTTP_CONTENT_CHARSET, UTF8);// 对含有中文的字符进行编码
    client.setConnectionTimeout(1000 * 60); // 设置超时时间 1分钟
    int status = 0;
    status = client.executeMethod(postMethod);
    if (status != 200) {// 连接失败
    // System.out.println("responseMsg:服务器内部错误!!!");
    throw new Exception("服务器内部错误!!!");
    }
    byte[] responseBody = postMethod.getResponseBody();
    return new String(responseBody);
    } catch (Exception e) {
    e.printStackTrace();
    throw new Exception(e);
    } finally {
    // 6.释放连接
    postMethod.releaseConnection();
    }
    }

    //map2json方法

    private static String Map2JSON(Map<String, String> params) throws Exception {
    Map<String, String> treeMap = new TreeMap<String, String>();
    treeMap.putAll(params);
    treeMap.put("sign", digest(getBeforeSign(treeMap).toString()));
    return JSON.toJSONString(treeMap);
    }

    public static Map updatePassWord(String empName, String passWord,
    String modiPerson) {
    Map<String, String> params = new HashMap<String, String>();
    params.put("empName", empName);
    params.put("empPassword", passWord);
    params.put("modiPerson", modiPerson);
    Map map = new HashMap();
    try {
    String jsonStr = URLDecoder.decode(
    doGetResult(URL_UPPASSWORD, params), "UTF-8");
    map = JSON.parseObject(jsonStr, Map.class);
    } catch (Exception e) {
    e.printStackTrace();
    map.put(RESP_STATUS, FAiL_SIGN);
    map.put(RESP_MSG, e.getMessage());
    }
    return map;
    }

  • 相关阅读:
    我的前端分页
    我所常用的分页
    glyphicons-halflings-regular.woff 404
    ueditor样式过滤问题
    图片延迟加载和滑动翻页
    我所常用的ajax调用格式
    使用UEditor无法SetContent的问题
    ajaxSubmit与ajaxFileUpload的空值
    SQL关于日期的查询
    【POJ 3071】 Football(DP)
  • 原文地址:https://www.cnblogs.com/lizihao/p/5505822.html
Copyright © 2020-2023  润新知