• ADADADADAD

    Java怎么调用HTTPS的接口[ 网络知识 ]

    网络知识 时间:2024-11-20 12:07:32

    作者:文/会员上传

    简介:

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

    以下为本文的正文内容,内容仅供参考!本站为公益性网站,复制本文以及下载DOC文档全部免费。

    在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;

    }

    }

    Java怎么调用HTTPS的接口.docx

    将本文的Word文档下载到电脑

    推荐度:

    下载
    热门标签: httpsJava