中文字幕av专区_日韩电影在线播放_精品国产精品久久一区免费式_av在线免费观看网站

溫馨提示×

Java怎么調用HTTPS的接口

九三
3744
2021-02-23 14:26:08
欄目: 編程語言

Java怎么調用HTTPS的接口

在Java中使用HttpClient調用HTTPS接口,具體方法如下:

import org.apache.http.HttpEntity;

import org.apache.http.HttpResponse;

import org.apache.http.StatusLine;

import org.apache.http.client.HttpClient;

import org.apache.http.client.methods.HttpPost;

import org.apache.http.entity.StringEntity;

import org.apache.http.message.BasicHeader;

import org.apache.http.util.EntityUtils;

public class HttpClientUtil {

@SuppressWarnings("resource")

public static String doPost(String url,String jsonstr,String charset){

HttpClient httpClient = null;

HttpPost httpPost = null;

String result = null;

try{

httpClient = new SSLClient();

httpPost = new HttpPost(url);

httpPost.addHeader("Content-Type", "application/json");

StringEntity se = new StringEntity(jsonstr);

se.setContentType("text/json");

se.setContentEncoding(new BasicHeader("Content-Type", "application/json"));

httpPost.setEntity(se);

HttpResponse response = httpClient.execute(httpPost);

if(response != null){

HttpEntity resEntity = response.getEntity();

if(resEntity != null){

result = EntityUtils.toString(resEntity,charset);

}

}

}catch(Exception ex){

ex.printStackTrace();

}

return result;

}

}

0
炉霍县| 德安县| 霍州市| 渭南市| 尚志市| 宿松县| 大洼县| 贞丰县| 金山区| 社旗县| 卢龙县| 仁布县| 随州市| 都昌县| 延吉市| 璧山县| 平山县| 苍山县| 名山县| 怀安县| 光泽县| 大邑县| 绥阳县| 合川市| 府谷县| 武义县| 治县。| 肇庆市| 定结县| 扎囊县| 旬邑县| 什邡市| 永顺县| 桂阳县| 梁平县| 霞浦县| 蛟河市| 永宁县| 张掖市| 南丹县| 泗洪县|