HttpClient的PostMethod请求请求体传递参数

工作中遇到使用Postmethod请求,参数以body形式进行传递,记录下,以免以后忘记,话不多说,直接上代码

PostMethod postMethod = new PostMethod("url");

            RequestEntity se = new StringRequestEntity(JSONObject.toJSON(esFinanceParamDTO).toString(), "application/json", "UTF-8");
            postMethod.setRequestEntity(se);
            httpclient.executeMethod(postMethod);
            String respstr = postMethod.getResponseBodyAsString();
            System.out.println(respstr);
       

备注:esFinanceparamDTO是请求需要传递的参数对象,转成json进行传递

猜你喜欢

转载自blog.csdn.net/weixin_41818715/article/details/82423578
今日推荐