展开全部
public String postRequest(String address,String data) throws IOException{
URL url = new URL(address);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("POST");
con.setDoOutput(true);
con.setReadTimeout(30000);
con.setConnectTimeout(30000);
con.connect();
// 发送json数据
OutputStream out = con.getOutputStream();
out.write(data.getBytes("UTF-8"));
out.flush();
out.close();
// 获取响应数据
InputStream in = con.getInputStream();
Reader reader = new InputStreamReader(in, "UTF-8");
BufferedReader bufferedReader = new BufferedReader(reader);
StringBuffer sb = new StringBuffer();
String temp = null;
while ((temp = bufferedReader.readLine()) != null) {
sb.append(temp);
}
bufferedReader.close();
con.disconnect();
return sb.toString();
}
以上是请求接e69da5e887aa62616964757a686964616f31333363356631口方法,还有就是从request对象中获取inputStream对象,处理方法和“// 获取响应数据"一致InputStream in = request.getInputStream();