httppost请求“Content-Type“,“application/x-www-form-urlencoded;charset=utf-8“参数传递

在HTTP POST请求中,使用"Content-Type":"application/x-www-form-urlencoded;charset=utf-8"时,原始参数如"啊啊啊啊啊"会被转化为"%E7%B2%A4LX255Q"的格式。为了解码这类字符串,可以利用URLDecoder的decode方法将application/x-www-form-urlencoded MIME字符串还原为普通字符串。反之,若要编码普通字符串,可使用URLEncoder的encode方法将其转换成符合MIME类型的格式。
摘要由CSDN通过智能技术生成

  "Content-Type","application/x-www-form-urlencoded;charset=utf-8"

	/** 
	 * 请求服务   "Content-Type","application/x-www-form-urlencoded;charset=utf-8"
	 *
	 * @return
	 */
	public  static String httpPost(String url,Map<String,String> param,String appkey){

		HttpPost httpPost = new HttpPost(url);
		httpPost.setHeader("appkey",appkey);
		ArrayList<BasicNameValuePair> list = new ArrayList<>();
		param.forEach((key, value) -> list.add(new BasicNameValuePair(key, value)));
		CloseableHttpClient httpClient = HttpClients.createDefault();
		try {
			if (Objects.nonNull(param) && param.size() >0) {
				httpPost.setEntity(new UrlEncodedFormEntity(list, "UTF-8"));
			}
			/*InputStream content = httpPost.getEntity().getContent();
			InputStreamReader inputStreamReader = new InputStreamReader(content, "UTF-8");
			BufferedRead
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值