云服务器网:购买云服务器和VPS必上的网站!

接口:Java如何调用HTTPS的接口

Java如何调用HTTPS的接口在Java中使用HttpClient调用HTTPS接口,具体方法以下:import org.apache.http.HttpEntity;import org.apache.http.HttpResponse;import or

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;

}

}

本文来源:https://www.yuntue.com/post/59562.html | 云服务器网,转载请注明出处!

关于作者: yuntue

云服务器(www.yuntue.com)是一家专门做阿里云服务器代金券、腾讯云服务器优惠券的网站,这里你可以找到阿里云服务器腾讯云服务器等国内主流云服务器优惠价格,以及海外云服务器、vps主机等优惠信息,我们会为你提供性价比最高的云服务器和域名、数据库、CDN、免费邮箱等企业常用互联网资源。

为您推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注