All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.liumapp.datapay.sms.tool.HttpPost Maven / Gradle / Ivy

There is a newer version: v2.0.5
Show newest version
package com.liumapp.datapay.sms.tool;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;

import java.io.InputStream;
import java.util.List;

import static com.liumapp.datapay.sms.tool.Convert.convertStreamToString;

/**
 * Created by haoxy on 2018/11/3.
 * E-mail:[email protected]
 * github:https://github.com/haoxiaoyong1014
 */
public class HttpPost {

    public static String httpPost(String url,List params) {
        String result = "";
        try {
            CloseableHttpClient httpclient = HttpClients.createDefault();
            //HttpClient httpclient = new DefaultHttpClient();
            org.apache.http.client.methods.HttpPost httpPost = new org.apache.http.client.methods.HttpPost(url);
            httpPost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
            HttpResponse response = httpclient.execute(httpPost);
            HttpEntity entity = response.getEntity();
            if (entity != null) {
                InputStream instreams = entity.getContent();
                result = convertStreamToString(instreams);
                System.out.println(result);
            }
        } catch (Exception e) {
        }
        return result;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy