标签:
本文采用httpcomponents-client-4.4.1 原名http client
发送post数据时,一般会对数据进行urlencode转码---URLEncode或UrlEncodedFormEntity。
下面几项用于设置http请求头的编码或请求内容属性,具体的请自行百度。
// .addHeader("Accept-Charset", "utf-8") //fail
// .addHeader("Content-Type","text/plain;charset=UTF-8")//fail
// .addHeader("Content-Type","application/x-www-form-urlencoded")
static void t3(){ StringBuffer mobiles = new StringBuffer() .append("13581xxxxxx").append(",") .append("18669xxxxxx").append(",") .append("13121xxxxxx").append(",") .append("18210xxxxxx").append(",") .append("15811xxxxxx").append(",") .append("15331xxxxxx").append(",") .append("18501xxxxxx").append(",") .append("13699xxxxxx").append(",") .append("18500xxxxxx").append(",") .append("18310xxxxxx").append(",") .append("13581xxxxxx"); String msg = "员工您好,感谢您对此次测试的配合。"; List<NameValuePair> ls = new ArrayList<>(); ls.add(new BasicNameValuePair("userId", "Jxxxx")); ls.add(new BasicNameValuePair("password", "5xxx3")); ls.add(new BasicNameValuePair("mobis", mobiles.toString())); ls.add(new BasicNameValuePair("msg", msg)); ls.add(new BasicNameValuePair("mobiCount", "" + 11)); ls.add(new BasicNameValuePair("aubPort", "*")); ls.add(new BasicNameValuePair("msgId", "98xxxx31")); try { HttpEntity entity = Request.Post("http://61.1xx.xxx.29:xxxx/Mxxx/wxxx.axxx/MxxxxxSubmit") .connectTimeout(3000) .body(new UrlEncodedFormEntity(ls,"UTF-8")) .execute().returnResponse().getEntity(); entity.writeTo(System.out); } catch (Exception e) { e.printStackTrace(); } }
标签:
原文地址:http://my.oschina.net/tangcoffee/blog/408714