我收到此异常:java.net.ProtocolException:流W/System.err的意外结束:okhttp3.internal.http1.Http1ExchangeCodec$FixedLengthSource.read(Http1ExchangeCodec.kt:392)
我正在尝试执行 SOAP 请求。我并不总是得到这个例外。有时我从网络服务器得到正确的答案。
我将解析器库从SimpleXML更改为TikXML,但我仍然遇到同样的问题。在on响应方法上,我什么也没做,但我遇到了同样的问题。
我是这样打电话的:
final Call<ResponseEnvelope> consumeWS = RetrofitGenerator
.getConsultarTipoDeDocumentoApi()
.getTiposDeDocumento(this.USERNAME_ENCRYPT, this.USERTOKEN_ENCRYPT,
this.MESSAGEID_ENCRYPT, "close", this.requestEnvelope);
consumeWS.enqueue(new Callback<ResponseEnvelope>() {
@Override
public void onResponse(Call<ResponseEnvelope> call, Response<ResponseEnvelope> response) {
ResponseEnvelope responseEnvelope = new ResponseEnvelope(response.body().getBody());
if(responseEnvelope != null && response.isSuccessful())
dataTipoDeDocumento.setValue(responseEnvelope.getBody().getMtrtipdoccResponse()
.getReturn().getLISTAREGISTROS().getLIST());
}
@Override
public void onFailure(Call<ResponseEnvelope> call, Throwable t) {
t.printStackTrace();
dataTipoDeDocumento.setValue(null);
这是我的改造发电机:
private static OkHttpClient.Builder okHttpClient = new OkHttpClient
.Builder();
private static Retrofit.Builder retrofitBuilder = new Retrofit.Builder()
.addConverterFactory(SimpleXmlConverterFactory.create(serializer));
public RetrofitGenerator() {
}
public static <S> S createService(Class<S> serviceClass, String baseUrl) {
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
logging.level(HttpLoggingInterceptor.Level.BODY);
OkHttpClient client = okHttpClient
.connectTimeout(5, TimeUnit.SECONDS)
.writeTimeout(5, TimeUnit.SECONDS)
.readTimeout(5, TimeUnit.SECONDS)
.retryOnConnectionFailure(true)
.addInterceptor(logging)
.build();
Retrofit retrofit = retrofitBuilder.baseUrl(baseUrl).client(client).build();
return retrofit.create(serviceClass);
}
问题是:(调试请求)
override fun read(sink: Buffer, byteCount: Long): Long {
require(byteCount >= 0L) { "byteCount < 0: $byteCount" }
check(!closed) { "closed" }
if (bytesRemaining == 0L) return -1
val read = super.read(sink, minOf(bytesRemaining, byteCount))
if (read == -1L) {
realConnection!!.noNewExchanges() // The server didn't supply the promised content length.
val e = ProtocolException("unexpected end of stream")
responseBodyComplete()
throw e
}
我注意到,当它失败时,有一个名为bytesRemaining的变量获取值1(当它失败的时候,它总是1)。回复的内容长度总是933。我不知道发生了什么。
这是我的毕业生:
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.app.multired"
minSdkVersion 22
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
dataBinding {
enabled = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation 'com.google.android.material:material:1.0.0'
implementation 'com.jakewharton:butterknife:10.0.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.0.0'
/* dagger dependency for DI*/
implementation "com.google.dagger:dagger:2.16"
annotationProcessor "com.google.dagger:dagger-compiler:2.16"
compileOnly 'javax.annotation:jsr250-api:1.0'
implementation 'javax.inject:javax.inject:1'
/*Retrofit lib*/
testImplementation 'com.squareup.okhttp3:mockwebserver:4.2.0'
implementation 'com.squareup.okhttp3:okhttp:4.2.0'
implementation 'com.squareup.retrofit2:retrofit:2.6.1'
implementation 'com.squareup.okhttp3:logging-interceptor:4.2.0'
//implementation 'com.squareup.okhttp3:okhttp:3.12.0'
implementation 'com.squareup.retrofit2:converter-simplexml:2.6.1'
/*RxJava lib*/
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
implementation "io.reactivex.rxjava2:rxjava:2.1.8"
implementation 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0'
/* LiveData lib*/
implementation "android.arch.lifecycle:extensions:1.1.1"
implementation "android.arch.lifecycle:runtime:1.1.1"
annotationProcessor "android.arch.lifecycle:compiler:1.1.1"
implementation 'androidx.recyclerview:recyclerview:1.0.0'
/* Biometric Authentication */
implementation 'androidx.biometric:biometric:1.0.0-alpha03'
implementation 'org.jetbrains:annotations:15.0'
}
我是如何解决的:
public abstract class CallbackWithRetry<T> implements Callback<T> {
private static final String TAG = CallbackWithRetry.class.getSimpleName();
@Override
public void onFailure(Call<T> call, Throwable t){
Log.e(TAG, t.getLocalizedMessage());
retry(call);
}
private void retry(Call<T> call){
call.clone().enqueue(this);
}
}
编辑后的回调:
final Call<ConsultarTipoDeDocumentoResponseEnvelope> consumeWS = RetrofitGenerator
.getConsultarTipoDeDocumentoApi()
.getTiposDeDocumento(this.USERNAME_ENCRYPT, this.USERTOKEN_ENCRYPT,
this.MESSAGEID_ENCRYPT, this.consultarTipoDeDocumentoRequestEnvelope);
consumeWS.enqueue(new CallbackWithRetry<ConsultarTipoDeDocumentoResponseEnvelope>() {
@Override
public void onResponse(Call<ConsultarTipoDeDocumentoResponseEnvelope> call, Response<ConsultarTipoDeDocumentoResponseEnvelope> response) {
ConsultarTipoDeDocumentoResponseEnvelope consultarTipoDeDocumentoResponseEnvelope = new ConsultarTipoDeDocumentoResponseEnvelope(response.body().getBody());
if(consultarTipoDeDocumentoResponseEnvelope != null && response.isSuccessful())
dataTipoDeDocumento.setValue(consultarTipoDeDocumentoResponseEnvelope.getBody().getMtrtipdoccResponse()
.getReturn().getLISTAREGISTROS().getLIST());
}
@Override
public void onFailure(Call<ConsultarTipoDeDocumentoResponseEnvelope> call, Throwable t) {
super.onFailure(call, t);
}
});
此重试非常有用,因为RetroFit2在执行入队调用时将调用变量作为onFailure方法的参数包含在内。
我的猜测是服务器使用String测量了响应长度。length()
(或类似),但内容并非全部为ASCII,因此以字节为单位的编码长度更大。
您可以通过查看损坏的响应中是否有任何非 ASCII 字符来确认这一点。
我得到意外结束流,而使用改造(2.9.0)与OkHttp3(4.9.1) 改装配置: 到目前为止,我发现了以下几点: 这个问题只发生在我使用从Windows系列操作系统(7、10、11)运行的Android Studio模拟器时——这是在来自不同网络的两台不同笔记本电脑上复制的 如果在苹果操作系统下运行Android Studio模拟器,那么在所有情况下,问题都不会再现 ARC/Postman客户
我已经按照此链接刷新了访问令牌。在将身份验证器添加到okHttp时,从改造回调onFailure方法中获取okhttp3上的意外流结束错误
问题内容: Redis 3.0.5 Spring数据Redis 1.3.6 jedis 2.6.3- 我们的Web应用程序,它通过pub / sub从redis接收数据。 -还以键/值对的形式对redis进行数据读/写。 -读/写发生在侦听器线程,独立监视线程和http请求线程上。 -我们对侦听器和Redis模板使用了相同的连接工厂 -我们的Redis服务器已配置“ timeout = 30” 在
我读过其他线程,谈到使用单线程进行读/写。但是在我们的情况下,很难使用单线程。同样,根据RedisTemplate文档,它是线程安全的。该问题是偶然的,我们无法在任何开发/测试/UAT环境中重现。因此无法找到相同的确切原因。我们做错了什么?
问题内容: 有什么问题或。请阅读以下代码(或运行它,看看会发生什么): 它创建一个文件,通过GZIP 写入单个字节格式,并以相同格式读取同一文件中的字节。 这就是我运行的内容: 由于某些原因,阅读线似乎走错了路。 我搜索了该错误,并发现了一些有关Oracle的错误报告,这些错误报告是在2007-2010年间发布的。因此,我认为该错误仍然存在,但是我不确定我的代码是否正确,因此让我在此处发布并听
当我发现这个的时候,我已经有一段时间了。使用swankjesse提供的解决方案后,错误消失了。我只是不明白为什么这是一个解决办法。我在网上找不到任何解释这种方法解决错误的原因的东西。
问题内容: 我正在使用fetch()从api服务器获取数据。我的错误如下所示: 你能告诉我我在做什么错。 问题答案: 一种用于响应请求到跨源资源具有“不透明”的响应类型。如果在尝试将响应转换为JSON之前记录响应,您将看到一种“不透明”的类型。 不透明类型被列为“严重受限”。 不透明的已过滤响应是已过滤的响应,其类型为“不透明”,URL列表为空列表,状态为0,状态消息为空字节序列,标头列表为空,主
我使用fetch()从api服务器获取数据。我的错误是这样的: 你能告诉我我做错了什么吗。