有关接口的
public InputStream post(String strURL, String params) {
HttpURLConnection connection=null;
InputStream inputStream = null;
try {
URL url = new URL(strURL);// 创建连接
connection = (HttpURLConnection) url
.openConnection();
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setUseCaches(false);
connection.setInstanceFollowRedirects(true);
connection.setRequestMethod("POST"); // 设置请求方式
connection.setRequestProperty("Accept", "application/json"); // 设置接收数据的格式
connection.setRequestProperty("Content-Type", "application/json"); // 设置发送数据的格式
connection.connect();
OutputStreamWriter out = new OutputStreamWriter(
connection.getOutputStream(), "UTF-8"); // utf-8编码
out.append(params);
out.flush();
out.close();
}catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally {
if (connection != null) {
connection.disconnect();
}
}
//读取返回内容
try {
//读取返回内容
inputStream = connection.getInputStream();
} catch (Exception e) {
e.printStackTrace();
}
return inputStream;
}
这是我发送post请求的方法
// 设置编码
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
// 接收json
StringBuffer info = new StringBuffer();
InputStream in = request.getInputStream();
BufferedInputStream buf = new BufferedInputStream(in);
byte[] buffer = new byte[1024];
int iRead;
while ((iRead = buf.read(buffer)) != -1) {
info.append(new String(buffer, 0, iRead, "UTF-8"));
}
这是我的接收方法
这是一个接口,别人访问我的我接收完毕处理完数据后,怎么反馈给他一个json结果,并且让他能在发送post请求方法里面接收到,求详细