【发布时间】:2018-01-31 23:42:35
【问题描述】:
我有网络服务 URL,它工作正常。它提供 JSON 数据。
当我使用HttpURLConnection 和InputStream 时,我收到此错误:
java.io.IOException: unexpected end of stream on
Connection{comenius-api.sabacloud.com:443, proxy=DIRECT
hostAddress=12.130.57.1
cipherSuite=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 protocol=http/1.1}
(recycle count=0)
我的代码:
try {
URL url = new URL("https://comenius-api.sabacloud.com/v1/people/username=" + username + ":(internalWorkHistory)?type=internal&SabaCertificate=" + certificate);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
InputStream ist = con.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(ist));
while ((singleLine = reader.readLine()) != null) {
data = data + singleLine;
Log.e("Response", data);
}
} catch (Exception e) {
e.printStackTrace();
}
如何解决这个问题?
【问题讨论】:
-
你不能。这是服务器错误。
-
有其他解决方案吗?
-
尝试使用
OkHttp。它有时对我有用,但我不保证。 -
@phaneendratatapudi 如何解决这个错误?
-
如果 localhost 发生这种情况,我正在使用 xampp 并得到相同的错误,但是当我使用 Postman 时它工作得很好.. Android 连接问题?
标签: android rest inputstream httpurlconnection