网上太多php的,java的完全找不到,测试了几天,这个行得通,注意下方红色文字
/**
* 购买产品下单}
/**
* 微信接口基础post请求
* @param args[接口path,xmlbody参数]
* @return json字符串
* @throws ClientProtocolException
* @throws IOException
*/
private static final String postpay(String path,String xml){
try{
HttpPost post = new HttpPost(String.format(PAYBASE, path));
StringEntity entity = new StringEntity(xml,"iso8859-1");
entity.setContentEncoding("utf-8");
entity.setContentType("text/xml");
post.setEntity(entity);
return EntityUtils.toString(new DefaultHttpClient().execute(post).getEntity(),"utf-8");
}catch(Exception e){
return String.format("{\"exception\":\"%s\"}", e.getMessage());
}
}
原文地址:http://blog.csdn.net/yklfxy/article/details/46010733