日期:2014-05-19 浏览次数:20884 次
String reportJson ="json内容......"
String reportType = "类型";
HttpURLConnection con =
(HttpURLConnection)new URL("http://localhost:8080/restful/data").openConnection();
con.setRequestMethod("POST"); //设置为post提交
con.setRequestProperty("type", reportType ); //设置header["类型"]
BufferedWriter bout = new BufferedWriter(new OutputStreamWriter(con.getOutputStream()));
bout.write(reportJson);
bout.flush();
bout.close();
// 取得输入流,并使用Reader读取
BufferedReader reader = new BufferedReader(new InputStreamReader(
con.getInputStream()));
String lines;
while ((lines = reader.readLine()) != null) {
System.out.println(lines);
}
reader.close();