JAVA获取别人发过来的json字符串(Post方式)

这几天做一个通知接口,其他服务器会向我的服务器发送通知,是Post方式,是json字符串

找了好多方法都不行,功夫不负有心人,终于找到合适的方法:

代码如下:

    使用的是request的输入流来写的,记得要写utf-8接收,不然有可能是乱码

                InputStreamReader insr = new InputStreamReader(request.getInputStream(),"utf-8");
//读取服务器的响应内容并显示
String result = "";
int respInt = insr.read();
System.out.println(respInt);
while(respInt != -1){
result += (char)respInt;
respInt = insr.read();
}
System.out.println("result:" + result);

猜你喜欢

转载自blog.csdn.net/u013294097/article/details/80353948