zoukankan      html  css  js  c++  java
  • httpclient的调用 发送json字符串

    public static String postHttp(JSONObject jsonObject, String jsonUrl){

    String responseMsg="";


    //获取http连接
    HttpClient httpClient = new HttpClient();

    httpClient.getParams().setContentCharset("utf-8");

    //2.构造PostMethod的实例
    PostMethod postMethod=new PostMethod(jsonUrl);

    try {

    String postJson = jsonObject.toJSONString();

    RequestEntity se = new StringRequestEntity(postJson, "application/json", "UTF-8");

    //url设置json参数
    postMethod.setRequestEntity(se);

    postMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler());

    try {
    //发送url 单独处理该异常
    httpClient.executeMethod(postMethod);//200
    } catch (Exception e) {
    try {
    httpClient.executeMethod(postMethod);//200
    } catch (Exception e2) {
    try {
    httpClient.executeMethod(postMethod);//200
    } catch (Exception e3) {
    log.error("连续3次连接异常,终止数据推送...",e);
    }
    }
    }

    responseMsg=postMethod.getResponseBodyAsString().trim();

    } catch (Exception e) {
    e.printStackTrace();
    }finally{
    //7.释放连接
    postMethod.releaseConnection();
    }
    return responseMsg;


    }

  • 相关阅读:
    html5——渐变
    html5——背景
    html5——边框
    html5——私有前缀
    html5——盒子模式
    html5——文本阴影
    html5——颜色
    html5——css选择器
    html5——DOM扩展
    html5——多媒体(一)
  • 原文地址:https://www.cnblogs.com/wangzheguilai/p/8136871.html
Copyright © 2011-2022 走看看