HttpClient

 

 

----------------用list传参数--------------

String urls="";

HttpPost httpPost = new HttpPost(urls);

httpPost.setHeader("Content-type","application/x-msdownload;charset=utf-8");

List<NameValuePair> list = new ArrayList<>();

list.add(new BasicNameValuePair("username","123"));

list.add(new BasicNameValuePair("password","456"));

UrlEncodedFormEntity urlEncodedFormEntity = new UrlEncodedFormEntity(list, Consts.UTF_8);

httpPost.setEntity(urlEncodedFormEntity);

-------------------------------------------------传json,与外部系统对接时这种方式比较多。-----------------------------------------

原文地址:https://www.cnblogs.com/zhuxiang1029/p/15247941.html