相关疑难解决方法(0)

如何在Android模拟器中连接localhost?

我在localhost中创建了一个php脚本,我正在连接它,httpClient但是我遇到了问题.

请告诉我如何从模拟器连接到localhost的php文件?

localhost httpconnection android-emulator androidhttpclient

99
推荐指数
7
解决办法
6万
查看次数

java.net.ProtocolException:意外的流结束

我面临一个奇怪的问题,我无法调试它.我已经实现用于上载的数据的流,并且正在使用排球对于相同的逻辑,我已经定制的逻辑点点HurlStack,addBodyIfExistsAPI,所以类型"application /八位字节流"的该机构可以处理.

我的逻辑是将进度发布给用户,以便可以更新UI,指示用户在上传中的进度,低于我的逻辑.

            int toRead = length; // File length
            byte[] data = new byte[4096];
            connection.setDoOutput(true);
            if(length != -1) {
                connection.setFixedLengthStreamingMode(length);
            } else {
                connection.setChunkedStreamingMode(4096);
            }

            OutputStream os;
            int i;
            int count;

            os = connection.getOutputStream();
            int progress= 0;

               try {
                    for(i = 0; (count= is.read(data)) > 0; ++i) { // is, is not null and contains a valid input stream
                        os.write(data, 0, count); // at this line am getting unexpected end of stream
                        progress+= count;
                        if(i …
Run Code Online (Sandbox Code Playgroud)

android android-volley okhttp

10
推荐指数
1
解决办法
2万
查看次数

改造 POST java.io.IOException:由 java.io.EOFException 引起的连接上的流意外结束:\n 未找到:

我已经完成了与此相关的所有问题,但是,我还没有找到适合我的解决方案。

我正在使用retrofit 2.8.1OkHttp 4.5.0

我的服务界面如下所示

public interface MlApiService
{
    @POST
    @Multipart
    Call<List<PreprocessedDocument>> postDocument( @Url String apiUrl, @Part MultipartBody.Part document,
    @Part ( "document_id") RequestBody documentId );
}
Run Code Online (Sandbox Code Playgroud)

我构建了客户端,如下所示,requestTimeoutInSeconds设置为 90 秒。

public void init()
{
    GsonBuilder gson = new GsonBuilder();
    gson.registerTypeAdapter( new TypeToken<List<PreprocessedDocument>>() {}.getType(), new CustomResponseDeserializer() );

    HttpLoggingInterceptor logInterceptor = new HttpLoggingInterceptor();
    logInterceptor.setLevel( HttpLoggingInterceptor.Level.HEADERS );

    OkHttpClient client = new OkHttpClient.Builder().retryOnConnectionFailure( true ).addInterceptor( logInterceptor )
        .readTimeout( requestTimeoutInSeconds, TimeUnit.SECONDS ).build();
    //Dummy Base URL must be provided. otherwise client …
Run Code Online (Sandbox Code Playgroud)

java gunicorn okhttp retrofit2

4
推荐指数
1
解决办法
4575
查看次数