亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

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
安化县| 独山县| 丽水市| 伊川县| 巴彦县| 出国| 凭祥市| 孝义市| 尼木县| 平原县| 德钦县| 兰考县| 长武县| 镇江市| 镇远县| 罗城| 太仓市| 潍坊市| 南充市| 永平县| 麦盖提县| 辉南县| 延津县| 贵港市| 韶山市| 博兴县| 阿城市| 涿鹿县| 尼木县| 普兰店市| 祁门县| 固原市| 宁明县| 门头沟区| 贵德县| 吉安市| 乌什县| 霍山县| 高陵县| 和林格尔县| 临安市|