我想在Android模拟器中使用浏览器,我想在我的机器上使用代理设置.我怎么设置它?
阅读非常好的Android手册,他们告诉我应该使用以下命令启动Android:
emulator -avd myavd -http-proxy http://168.192.1.2:3300
Run Code Online (Sandbox Code Playgroud)
但我仍然无法使用模拟器浏览器.请注意我正在使用我的代理服务器的IP地址.
我究竟做错了什么?
可能重复:
Android:"意外的流结束"异常下载大文件
我正在低估一个大约的档案.5MB使用HttpURLConnection但是在downlod期间的一半我在我的代码的这一行得到了"意外的流结束"错误:
while ((count = input.read(data)) > 0) {
Run Code Online (Sandbox Code Playgroud)
这是LOG:
11-20 16:05:55.749: ERROR/PRINTSTACK(3425): STACK:unexpected end of stream
11-20 16:05:55.749: WARN/System.err(3425): java.io.IOException: unexpected end of stream
11-20 16:05:55.749: WARN/System.err(3425): at org.apache.harmony.luni.internal.net.www.protocol.http.FixedLengthInputStream.read(FixedLengthInputStream.java:47)
11-20 16:05:55.749: WARN/System.err(3425): at java.io.BufferedInputStream.read(BufferedInputStream.java:319)
11-20 16:05:55.749: WARN/System.err(3425): at java.io.FilterInputStream.read(FilterInputStream.java:133)
11-20 16:05:55.759: WARN/System.err(3425): at com.conjure.skiproj.DownloadService$Job.process(DownloadService.java:265)
11-20 16:05:55.759: WARN/System.err(3425): at com.conjure.skiproj.DownloadService$1.run(DownloadService.java:193)
11-20 16:05:55.759: WARN/System.err(3425): at java.lang.Thread.run(Thread.java:1019)
Run Code Online (Sandbox Code Playgroud)
帮助!! 1
编辑:有关设置输入流的代码的更多信息:
HttpURLConnection conexion = (HttpURLConnection)url.openConnection();
conexion.setRequestMethod("GET");
conexion.setReadTimeout(20000);
conexion.connect();
File file = new File(root.getAbsolutePath()+"/", fileName);
int lenghtOfFile = conexion.getContentLength();
InputStream input …Run Code Online (Sandbox Code Playgroud) 我有一个 Android 应用程序,它向 Flask 中的 REST API 发出 http 请求。我使用 Retrofit2 和 okhttp3 向带有 Raspbian Lite 的 Raspberry Pi 上托管的服务器发出请求。我的问题是,有时我会收到 IOException -> java.net.ProtocolException: 意外的流结束 但它有时会发生,其他时候它工作得很好。http客户端构建如下:
OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
httpClient.addInterceptor(new Interceptor() {
@NotNull
@Override
public Response intercept(@NotNull Chain chain) throws IOException {
Request original = chain.request();
Request request = original.newBuilder()
.header("User-Agent","myUserAgent")
.header("Connection","close")
.addHeader("Accept-Encoding", "identity")
.method(original.method(),original.body())
.build();
return chain.proceed(request);
}
});
Retrofit retrofit=null;
try {
retrofit = new Retrofit.Builder()
.baseUrl(baseUrl)
.addConverterFactory(GsonConverterFactory.create())
.client(httpClient.build())
.build();
}catch (Exception e){
//Log.d
}
ApiService API_SERVICE=null; …Run Code Online (Sandbox Code Playgroud)