java.io.IOException: unexpected end of stream on Connection{116.220.68.11:8006, proxy=DIRECT

  • 当你通过URL请求服务器获取数据时,或许会遇到和我一样的问题
java.io.IOException: unexpected end of stream on Connection{116.220.68.11:8006, 
proxy=DIRECT@ hostAddress=116.220.68.11 cipherSuite=none protocol=http/1.1} (recycle count=0):

报错如下:
这里写图片描述

报错的最大原因之一是URL不合法,可能你携带的参数有不合法的符号,例如携带了时间参数:
String url = "http://test/request?id=101&time=2018-8-29 12:12:00";
因为时间 2018-8-29 12:12:00 中间有空格,请求时无法识别那个空格符号,所以你要做的是将时间进行URLEncoder编码:
    String time = URLEncoder.encode("2018-8-29 12:12:00", "UTF-8");
    String url = "http://test/request?id=101&time=" + time;
  • Over.
发布了27 篇原创文章 · 获赞 32 · 访问量 7万+

猜你喜欢

转载自blog.csdn.net/luoyingxing/article/details/82179640
今日推荐