request.getInputStream()得不到值

用的HttpUrlConnection模拟请求
URL serverUrl = new URL("");
		HttpURLConnection conn = (HttpURLConnection) serverUrl.openConnection();

		conn.setRequestMethod("POST");
		conn.setDoOutput(true);
		
		conn.connect();
		String params = "hello";
		
		conn.getOutputStream().write(params.getBytes());
		conn.getOutputStream().flush();
		conn.getOutputStream().close();
		InputStream is = conn.getInputStream();

但是请求的接口,想获得inputStream为空,

解决方法:
新增Content-Type请求头,明确告诉服务器处理什么样的数据。

conn.setRequestProperty("content-type", "text/html");

猜你喜欢

转载自elena-me.iteye.com/blog/2292342