gpt4 book ai didi

inputstream - 读取 NANOHTTPD 的 InputStream 会出现 Socket TimeOut 异常

转载 作者:行者123 更新时间:2023-12-04 03:13:55 54 4
gpt4 key购买 nike

我正在尝试使用以下代码从 IHTTPSession.getInputStream() 读取 InputStream,但它每次都给出 Socket TimeOut Exception。

private String readInStream(InputStream in){

StringBuffer outBuffer=new StringBuffer();
BufferedInputStream bis=new BufferedInputStream(in);
try {
while(bis.available()>0){
int ch= bis.read();
outBuffer.append((char)ch);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

Log.e("DATA_Length", "outputBuffer :"+outBuffer.toString().length());
return outBuffer.toString();
}

我也尝试了以下方法,但出现了同样的异常
private String readInStream(InputStream in){
String line="";
StringBuffer outBuffer=new StringBuffer();

BufferedReader rd=new BufferedReader(new InputStreamReader(in));

try {
while((line=rd.readLine()) != null){
outBuffer.append(line);
}
} catch (IOException e) {
Log.e("IOException", "IOException in readInStream:");
e.printStackTrace();
}

Log.e("DATA_Length", "outputBuffer :"+outBuffer.toString().length());
return outBuffer.toString();
}

最佳答案

从标题中获取内容长度并阅读它解决了问题。

关于inputstream - 读取 NANOHTTPD 的 InputStream 会出现 Socket TimeOut 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24931470/

54 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com