91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

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
资源县| 城固县| 渝中区| 教育| 延川县| 象州县| 政和县| 高青县| 河北区| 珠海市| 新乐市| 乐山市| 综艺| 大余县| 隆德县| 内丘县| 梁山县| 忻城县| 镇原县| 津南区| 敦化市| 泉州市| 星子县| 年辖:市辖区| 加查县| 海伦市| 肃宁县| 房山区| 玉屏| 博湖县| 江安县| 三门峡市| 汝南县| 庄河市| 合阳县| 庐江县| 望都县| 乐业县| 抚顺市| 万年县| 江达县|