java - Java,我无法在控制台上打印整个响应
问题描述
我无法在控制台上打印来自服务器的整个响应!,有3种方法可以绕过这件事,
- 添加此标题连接:关闭
- 将HTTP/1.1替换为HTTP/1.0
- 添加这个s.close(); // Socket.close();
我无法关闭连接,因为我想在同一个连接上发送多次,
我只想打印整个响应而不关闭连接。
这是我的代码:
String Ch2 = "";
sops.write(my_UTF8Byte);
while((Ch2 = reader.readLine()) != null){
System.out.println(Ch2);
//sops.write(my_UTF8Byte);
Thread.sleep(10);
}
//s.close(); This will solve the problem
解决方案
当您说不打印整个响应时,它缺少最后一行?通过一次执行一个字符而不是 readLine 来检查:
int ch;
while((ch = in.read()) != -1)
{
System.out.print((char)ch);
}
推荐阅读
- c++ - 如何在每个共享库中使用自己的静态库副本
- android - 使用终端命令构建 Android Apk 时出错
- python - 在神经网络中,如果输入 > 1 或 < -1,那么是否应该在传播之前应用激活函数?
- php - $request->all() 始终为空
- amazon-web-services - 如何对 AWS DynamoDB for AWS CLI 进行速率限制扫描?
- python - 清理不需要的scrapy结果行
- javascript - 如何在打字效果中显示输入的文本以及一些常量文本?
- spring-mvc - 即使我正在使用 Controller 注释,我也没有发现任何处理程序异常
- css - 字体显示未知属性 wordpress GoDaddy
- python - 使用 python 处理大型 excel 文件花费太多时间