henryyan
9/25/2012 - 11:10 AM

HttpClient请求

HttpClient请求

HttpClient httpclient = new DefaultHttpClient();
		String tpaFileSystemUrl = PropertyFileUtil.get("sub.system.tpa.file.bj.url") + "/servlet/create-directory-for-files";
		logger.debug("send request to {}", tpaFileSystemUrl);

		HttpPost httppost = new HttpPost(tpaFileSystemUrl);
		UrlEncodedFormEntity urlEncodedFormEntity = new UrlEncodedFormEntity(Arrays.asList(new BasicNameValuePair("data",
				paramtersString)));
		httppost.setEntity(urlEncodedFormEntity);
		HttpResponse response = httpclient.execute(httppost);

		HttpEntity entity = response.getEntity();
		if (entity != null) {
			String content = EntityUtils.toString(entity, "UTF-8");
			logger.debug("response content: {}", content);
			Map<String, Object> readValue = new ObjectMapper().readValue(content, new TypeReference<Map<String, Object>>() {
			});
			Set<Entry<String, Object>> entrySet = readValue.entrySet();
			for (Entry<String, Object> entry : entrySet) {
				logger.debug(String.format("response -> key: %s,  value: %s", entry.getKey(), entry.getValue()));
			}
		}