该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
package contract;
import com.alibaba.fastjson.JSON;
import static io.itit.itf.okhttp.PostRequest.logger;
import java.io.*;
import org.apache.http.client.methods.HttpPost;
import java.util.ArrayList;
import org.apache.http.HttpEntity;
import org.apache.http.NameValuePair;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;/**
*
* @author song
*/
public class contract { /**
*
* @param
* @return
*/
public static String main(String[] ask){
String url="";
String result = "";
HttpPost httppost=new HttpPost(url); //建立HttpPost对象
CloseableHttpClient client = HttpClients.createDefault();//创建HttpClient对象
try
{
//添加参数
java.util.ListparamsList = new ArrayList();
paramsList.add(new BasicNameValuePair("0001","你好,你叫什么名字"));
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(paramsList, "UTF-8"); //设置请求和传输时长
RequestConfig.Builder builder = RequestConfig.custom();
builder.setSocketTimeout(120000);
builder.setConnectTimeout(60000);
RequestConfig config = builder.build(); httppost.setEntity(entity);
httppost.setConfig(config); //发送Post
CloseableHttpResponse response = client.execute(httppost);
HttpEntity httpEntity = response.getEntity();
if (httpEntity != null) {
result = EntityUtils.toString(httpEntity, "UTF-8");
}
} catch (IOException e) {
} finally{
try {
client.close();
httppost.releaseConnection();
} catch (IOException e) {
logger.info(e.toString(), e);
}
}
}
}