title: How to fix IOException in retrofit
body: <p>i have been working on android project that has node.js backend that communicate with database in sql server and IOException keeps showing to me:</p>
  
  <pre><code>caused by java.io.EOFException: \n not found: limit=0 content=…
  </code></pre>
  
  <p>this is the whole stack trace:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>i been watching, reading tutorials to make sure that i build the API and the connection code right and reading other people that have the same problem and doing what they did none of this fixed my problem.</p>
  
  <p>this is my node.js code:</p>
  
  <pre><code>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)=&gt;{
               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)=&gt;{
    if(recordAdded.rowsAffected == 1){
      res.json(dataPost.firstName + "Registered as Seller.");
    }else{
      res.json(dataPost.firstName + "failed to register as Seller.");
    }})}
  </code></pre>
  
  <p>and this is my retrofit code:</p>
  
  <pre><code>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;
  }
  </code></pre>
  
  <p>this code how i get the data from the api:</p>
  
  <pre><code> 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 -&gt; {   // 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 -&gt; {   // onError method
                              Log.d(TAG, "onPreExecute getting api error");
                              throwable.printStackTrace();
                          }, () -&gt; {          // onComplete method
                              Log.d(TAG, "onPreExecute after getting data from api");
                              Handler handler = new Handler(Looper.getMainLooper());
                              handler.post(() -&gt; {
                                  if (progressDialog.isShowing())
                                      progressDialog.dismiss();
                              });
                              Log.d(TAG, "completed");
                          }));
  </code></pre>
  
  <p>i expect to see the new buyer is added to the buyer table in my database but this Exception prevent from adding the new buyer.</p>