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");