问题描述
- HttpURLConnection.getInputStream获取长度为-1
- 百度得知Android2.2以上使用getInputStream,需要加上
hc.setRequestProperty(""Accept-Encoding""identity"");
可是试了下还是不行。。。
URL url = new URL(s); HttpURLConnection hc = (HttpURLConnection)url.openConnection(); hc.setRequestMethod(""GET""); hc.setDoInput(true); hc.setUseCaches(false); hc.setInstanceFollowRedirects(true); hc.setRequestProperty(""Accept-Encoding""identity""); //加上 hc.setRequestProperty(""Host""api.yeelink.net""); hc.setRequestProperty(""U-ApiKey""4d968660ad88e84f2c66ee5723e60cf8""); hc.setRequestProperty(""Content-Length""0""); hc.setRequestProperty(""Connection""close""); hc.connect(); int streamLength = hc.getContentLength();
时间: 2024-09-08 06:44:07