gpt4 book ai didi

android - 如何在改造中修复 IOException

转载 作者:行者123 更新时间:2023-11-29 02:23:07 28 4
gpt4 key购买 nike

我一直在开发具有 node.js 后端的 android 项目,该后端与 sql server 中的数据库进行通信,并且 IOException 不断向我显示:

caused by java.io.EOFException: \n not found: limit=0 content=…

这是整个堆栈跟踪:

W/System.err: java.io.IOException: unexpected end of stream on Connection{10.0.2.2:1433, proxy=DIRECT hostAddress=/10.0.2.2:1433 cipherSuite=none protocol=http/1.1}
at okhttp3.internal.http1.Http1Codec.readResponseHeaders(Http1Codec.java:208)
at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.java:88)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:45)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
W/System.err: at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:126)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:254)
at okhttp3.RealCall.execute(RealCall.java:92)
at retrofit2.OkHttpCall.execute(OkHttpCall.java:180)
at retrofit2.adapter.rxjava2.CallExecuteObservable.subscribeActual(CallExecuteObservable.java:41)
at io.reactivex.Observable.subscribe(Observable.java:12036)
at retrofit2.adapter.rxjava2.BodyObservable.subscribeActual(BodyObservable.java:34)
W/System.err: at io.reactivex.Observable.subscribe(Observable.java:12036)
at io.reactivex.internal.operators.observable.ObservableSubscribeOn$SubscribeTask.run(ObservableSubscribeOn.java:96)
at io.reactivex.Scheduler$DisposeTask.run(Scheduler.java:579)
at io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:66)
at io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:57)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:272)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)


W/System.err: Caused by: java.io.EOFException: \n not found: limit=0 content=…
W/System.err: at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:236)
at okhttp3.internal.http1.Http1Codec.readHeaderLine(Http1Codec.java:215)
at okhttp3.internal.http1.Http1Codec.readResponseHeaders(Http1Codec.java:189)
... 29 more

我一直在观看、阅读教程以确保我正确构建了 API 和连接代码,并阅读了其他有同样问题的人并按照他们所做的去做,但这些都没有解决我的问题。

这是我的 node.js 代码:

var postData = req.body; // get post params
var userId = uid.v4();
const userExistQuery = 'SELECT email, first_name, last_name FROM User WHERE email = @email AND category = @category AND password = @password';
if(postData.category.valueOf() == new String("Seller").valueOf()){
connection.request()
.input('email', sql.VarChar(45), postData.email)
.input('password', sql.VarChar(45), postData.password)
.input('category', sql.VarChar(45), postData.category)
.query(userExistQuery)
.then((recordSet)=>{
if(recordSet.rowsAffected == 1){
res.json("Already registered as Seller.");
}else{
var streetNum = postData.streetNum;
var buildingNum = postData.buildingNum;
var apartmentNum = postData.apartmentNum;
var town = postData.town;
var governance = postData.governance;
var floorNum = postData.floorNum;
var poBox = postData.poBox;
var zipCode = postData.zipCode;
var creditInfo = postData.creditInfo;
const addSellerQuery =
'INSERT INTO Seller(seller_id, street#, building#, apartment#, town, governance, floor#, P.O_box, zip_code, credit_info, first_name, last_name, email, password, phone_number ,category) VALUES(@sellerId,@streetNum,@buildingNum,@apartmentNum,@town,@governance,@floorNum,@poBox,@zipCode,@creditInfo,@firstName,@lastName,@email,@password, @phoneNumber, @category)';
connection.request()
.input('sellerId', sql.VarChar(45), userId)
.input('streetNum', sql.VarChar(45), postData.streetNum)
.input('buildingNum', sql.VarChar(45), postData.buildingNum)
.input('apartmentNum', sql.VarChar(45), postData.apartmentNum)
.input('town', sql.VarChar(45), postData.town)
.input('governance', sql.VarChar(45), postData.governance)
.input('floorNum', sql.VarChar(45), postData.floorNum)
.input('poBox', sql.VarChar(45), postData.poBox)
.input('zipCode', sql.VarChar(45), postData.zipCode)
.input('creditInfo', sql.VarChar(45), postData.creditInfo)
.input('firstName', sql.VarChar(45), postData.firstName)
.input('lastName', sql.VarChar(45), postData.lastName)
.input('email', sql.VarChar(45), postData.email)
.input('password', sql.VarChar(45), postData.password)
.input('phoneNumber', sql.VarChar(45), postData.phoneNumber)
.input('category', sql.VarChar(45), postData.category)
.query(addSellerQuery)
.then((recordAdded)=>{
if(recordAdded.rowsAffected == 1){
res.json(dataPost.firstName + "Registered as Seller.");
}else{
res.json(dataPost.firstName + "failed to register as Seller.");
}})}

这是我的改造代码:

public static Retrofit getRetrofit() {
if (retrofit == null) {
OkHttpClient okHttpClient = new OkHttpClient().newBuilder()
.connectTimeout(120, TimeUnit.SECONDS)
.readTimeout(120, TimeUnit.SECONDS)
.writeTimeout(120, TimeUnit.SECONDS)
.build();
retrofit = new Retrofit.Builder()
.baseUrl("http://10.0.2.2:1433/")
.client(okHttpClient)
.addConverterFactory(ScalarsConverterFactory.create())
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.build();
}
return retrofit;
}

这段代码是我如何从 api 获取数据的:

 compositeSubs.add(myAPI.buyerSignUp(buyer.getEmail(), buyer.getName().split(" ")[0]
, buyer.getName().split(" ")[1], buyer.getPassword(), buyer.bringType(), buyer.getPhoneNumber())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(s -> { // onNext method
Log.d(TAG, "onPreExecute get data from api");
((AuthListener) callBack).onSignUp(s, compositeSubs, false);
Log.d(TAG, "onPreExecute after get data from api");
}, throwable -> { // onError method
Log.d(TAG, "onPreExecute getting api error");
throwable.printStackTrace();
}, () -> { // onComplete method
Log.d(TAG, "onPreExecute after getting data from api");
Handler handler = new Handler(Looper.getMainLooper());
handler.post(() -> {
if (progressDialog.isShowing())
progressDialog.dismiss();
});
Log.d(TAG, "completed");
}));

我希望看到新买家被添加到我数据库中的买家表中,但此异常阻止添加新买家。

最佳答案

您是否尝试过此处的解决方案? https://github.com/square/okhttp/issues/2738

关于android - 如何在改造中修复 IOException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53978341/

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