博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POST编程代码实现
阅读量:4288 次
发布时间:2019-05-27

本文共 1125 字,大约阅读时间需要 3 分钟。

public class DoPost {    public JSONObject GetOrder(String url,JSONObject jsonObject){        String url2 =  url;        String result = "";        JSONObject resJson = new JSONObject();        CloseableHttpClient httpClient = HttpClients.createDefault();        HttpPost post = new HttpPost(url2);        StringEntity entity = new StringEntity(jsonObject.toString(), "utf-8");//解决中文乱码问题        entity.setContentEncoding("UTF-8");        entity.setContentType("application/json");//设置文档类型        post.setEntity(entity);        try {            HttpResponse resultResponse = httpClient.execute(post);            if (resultResponse.getStatusLine().getStatusCode() == 200) {                String resData = EntityUtils.toString(resultResponse.getEntity());                resJson = JSON.parseObject(resData);            } else                post.abort();        } catch (ClientProtocolException e) {            e.printStackTrace();            result = e.getMessage().toString();        } catch (IOException e) {            e.printStackTrace();            result = e.getMessage().toString();        }        return resJson;    }

转载地址:http://ndlgi.baihongyu.com/

你可能感兴趣的文章
基于位置的点击模型
查看>>
链表操作算法题合集
查看>>
Crackme3 破解教程
查看>>
奖学金评比系统(数据库系统设计版)
查看>>
HTTP Live Streaming直播
查看>>
rtmp+fms rtmp 视频发布环境
查看>>
最简单的基于librtmp的示例:发布(FLV通过RTMP发布)
查看>>
Windows/Linux下引用jar包,并用javac/java编译运行
查看>>
HttpClient使用详解
查看>>
HttpClient详解(一)
查看>>
httpclient 请求http数据,json转map
查看>>
git 常用命令
查看>>
用递归方法建立二叉树
查看>>
用递归方法对二叉树进行先序、中序和后序遍历
查看>>
翻转二叉树
查看>>
逆序链表
查看>>
epoll 使用详解
查看>>
stl 中 set容器用法
查看>>
有序数组求交集
查看>>
文字常量区与栈
查看>>