public static String sendSZPost(String url, String params, String secretKey)
throws UnsupportedOperationException, IOException {
byte[] requestBytes = params.getBytes("utf-8"); // 将参数转为二进制流
HttpClient httpClient = new HttpClient();// 客户端实例化
PostMethod postMethod = new PostMethod(url);
// 设置请求头Authorization
postMethod.setRequestHeader("AuthToken", secretKey);
// 设置请求头 Content-Type
postMethod.setRequestHeader("Content-Type", "application/json;charset=utf-8");
InputStream inputStream = new ByteArrayInputStream(requestBytes, 0, requestBytes.length);
RequestEntity requestEntity = new InputStreamRequestEntity(inputStream, requestBytes.length,
"application/json; charset=utf-8"); // 请求体
postMethod.setRequestEntity(requestEntity);
httpClient.executeMethod(postMethod);// 执行请求
InputStream soapResponseStream = postMethod.getResponseBodyAsStream();// 获取返回的流
byte
java使用post调取接口
最新推荐文章于 2024-05-16 17:36:27 发布