java Post 发送数据乱码问题

List<NameValuePair> listParams = new ArrayList<NameValuePair>();
//			listParams.add(new BasicNameValuePair("m", m));
			if (params != null) {
				for (String name : params.keySet()) {
					listParams.add(new BasicNameValuePair(name, params
							.get(name)));
					// System.out.println("--------"+name+"--"+params.get(name));
				}
				// listParams.add(new BasicNameValuePair("p", "api"));
			}
			HttpPost request = null;
			try {
				UrlEncodedFormEntity entity = new UrlEncodedFormEntity(
						listParams,HTTP.UTF_8);
				request = new HttpPost(url);
				request.setEntity(entity);

			} catch (UnsupportedEncodingException e) {
				e.printStackTrace();
			}

 创建UrlEncodedFormEntity 时加编码方式,在将UrlEncodedFormEntity 设置到request中后即可


你可能感兴趣的:(java,编码,乱码)