接口post包的方式传输

Posted JLCUI

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了接口post包的方式传输相关的知识,希望对你有一定的参考价值。

   public static String doPostJson(String url, String param) {
		String responseBody = "";
		HttpPost httppost = new HttpPost(url);
		StringEntity entities = new StringEntity(param, "UTF-8");
		entities.setContentEncoding("UTF-8");
		entities.setContentType("application/x-www-form-urlencoded");
		httppost.setEntity(entities);
		ResponseHandler<String> responseHandler = new ResponseHandler<String>() {

			public String handleResponse(final HttpResponse response)
					throws ClientProtocolException, IOException {
				int status = response.getStatusLine().getStatusCode();
				if (status >= 200 && status < 300) {
					HttpEntity entity = response.getEntity();
					return entity != null ? EntityUtils.toString(entity)
							: null;
				} else {
					throw new ClientProtocolException(
							"Unexpected response status: " + status);
				}
			}
		};
		try {
			responseBody = new DefaultHttpClient().execute(httppost, responseHandler);
		} catch (SocketTimeoutException e) {
			e.printStackTrace();
			responseBody = "timeout";
			return responseBody;
		} catch (ClientProtocolException e) {
			e.printStackTrace();
			return responseBody;
		} catch (IOException e) {
			e.printStackTrace();
			return responseBody;
		}
		return responseBody;
	}

  

以上是关于接口post包的方式传输的主要内容,如果未能解决你的问题,请参考以下文章

web端调接口用angularJS的post请求,接口传输数据一般用啥加密方式呀?要后台java那边可逆的。

接口请求get与post的请求的区别

接口请求get与post的请求的区别

接口测试基础

vue中调用接口传输对象使用this.$http.get 和 this.$http.post

get和post提交方式的差别