NativeScript / NativeScript/NativeScript

Nativescript with Angular - Http call gives error - 'unexpected end of stream on com.android.okhttp.Address@1d8e59ae'

Open
#9,999 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug-pending-triage
Dominant language
TypeScript
Stars
25.7k
Forks
1.7k
Avg merge
1d 5h
Merged PRs (30d)
35

Description

Issue Description

I have a NativeScript with angular project. The backend is a rest api written in .NET CORE. I'm trying to make a HTTP call fom the nativescript frontend following the post method under 'request' section as described in the link: https://docs.nativescript.org/http.html#request

Whenever I make a call, I get error -
JS: ERROR Error: Uncaught (in promise): Error: java.io.IOException: unexpected end of stream on com.android.okhttp.Address@1d8e59ae
JS: Error: java.io.IOException: unexpected end of stream on com.android.okhttp.Address@1d8e59ae
JS: at onRequestComplete (file: src\webpack:\ns-blendedsupport-mvp\node_modules@nativescript\core\http\http-request\index.android.js:49:33)
JS: at Object.onComplete (file: src\webpack:\ns-blendedsupport-mvp\node_modules@nativescript\core\http\http-request\index.android.js:38:12)

Reproduction
app.module.ts

import { NgModule, NO_ERRORS_SCHEMA } from '@angular/core'
import { NativeScriptHttpClientModule } from "@nativescript/angular";
import { NativeScriptModule } from '@nativescript/angular'
import { NativeScriptCommonModule } from "@nativescript/angular";
import { NativeScriptRouterModule } from "@nativescript/angular";
import { NativeScriptFormsModule } from "@nativescript/angular";
import { AppRoutingModule } from './app-routing.module'

@NgModule({
bootstrap: [AppComponent],
imports: [
NativeScriptModule,
NativeScriptHttpClientModule,
NativeScriptCommonModule,
NativeScriptRouterModule,
NativeScriptFormsModule,
AppRoutingModule,
],
declarations: [AppComponent],
providers: [],
schemas: [NO_ERRORS_SCHEMA],
})
export class AppModule {}

authenticationservice.ts

import { Injectable } from '@angular/core';
import { Http, HttpResponse} from "@nativescript/core";
import { RouterExtensions } from "@nativescript/angular";

import { CommonCodeService } from "./common-code-service";
import { LoginRequestDTO, LoginResponseDTO } from "../data-models/login-model";

@Injectable({
providedIn: 'root'
})
export class AuthenticationService {

loginModelData: LoginRequestDTO = {
Username:"",
Password:""
}

loginResponseData: LoginResponseDTO = {
isLoginSuccess:false,
responseMessage:"",
userId:"",
token:"",
firstname:""
};

isLoginValid: boolean = false;

constructor(
private commonCodeService: CommonCodeService,
private router: RouterExtensions,) { }

login(username: string, password:string) {
this.loginModelData.Username=username;
this.loginModelData.Password=password;
let apiURL = "http://10.0.2.2:4001/api/Login/Login";
let data = JSON.stringify(this.loginModelData);

Http.request({
  url: apiURL,
  method: "POST",
  headers: {
    "Content-Type": "application/json"
  },
  content: data,
}).then(
  (response: HttpResponse) => {
    const result = response.content.toJSON();
    if(result!='' || result!=null)
    {
      this.loginResponseData = <LoginResponseDTO>result;
      if(this.loginResponseData.isLoginSuccess)
      {
        this.isLoginValid=true;
        this.router.navigate(["home"], { clearHistory: true });
      }
      else
      {
        this.isLoginValid=false;
        this.commonCodeService.alert(this.loginResponseData.responseMessage);
      }
    }
    else
    {
      this.commonCodeService.alert('User data not found. Please try again');
    }
  }
);

}
}

Relevant log output (if applicable)
JS: ERROR Error: Uncaught (in promise): Error: java.io.IOException: unexpected end of stream on com.android.okhttp.Address@1d8e59ae
  JS: Error: java.io.IOException: unexpected end of stream on com.android.okhttp.Address@1d8e59ae
  JS:     at onRequestComplete (file: src\webpack:\ns-blendedsupport-mvp\node_modules\@nativescript\core\http\http-request\index.android.js:49:33)
  JS:     at Object.onComplete (file: src\webpack:\ns-blendedsupport-mvp\node_modules\@nativescript\core\http\http-request\index.android.js:38:12)
Environment
package.json

{
"name": "ns-blendedsupport-mvp",
"main": "./src/main.ts",
"version": "1.0.0",
"private": true,
"dependencies": {
"@angular/animations": "~13.2.0",
"@angular/common": "~13.2.0",
"@angular/compiler": "~13.2.0",
"@angular/core": "~13.2.0",
"@angular/forms": "~13.2.0",
"@angular/platform-browser": "~13.2.0",
"@angular/platform-browser-dynamic": "~13.2.0",
"@angular/router": "~13.2.0",
"@auth0/angular-jwt": "^5.0.2",
"@nativescript/angular": "^14.0.4",
"@nativescript/core": "~8.2.0",
"@nativescript/theme": "~3.0.2",
"crypto-js": "^3.3.0",
"nativescript-audio": "^6.2.6",
"nativescript-gif": "^5.0.0",
"nativescript-ui-gauge": "^8.0.1",
"nativescript-vibrate": "^4.0.1",
"nativescript-videoplayer": "^5.0.1",
"rxjs": "~7.5.0",
"zone.js": "~0.11.5"
},
"devDependencies": {
"@angular-devkit/build-angular": "~13.2.0",
"@angular/compiler-cli": "~13.2.0",
"@nativescript/android": "8.2.3",
"@nativescript/types": "~8.2.0",
"@nativescript/webpack": "~5.0.6",
"@ngtools/webpack": "~13.2.0",
"typescript": "~4.5.5"
}
}

tsconfig.json

{
"compilerOptions": {
"module": "esnext",
"target": "es2017",
"moduleResolution": "node",
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"noEmitHelpers": true,
"importHelpers":true,
"noEmitOnError": true,
"skipLibCheck": true,
"lib": ["es2017", "dom"],
"baseUrl": ".",
"paths": {
"~/": ["src/"],
"@/": ["src/"]
}
},
"include": ["src/tests//*.ts", "src//.ios.ts", "src/**/.android.ts"],
"files": ["./src/main.ts", "./references.d.ts", "./src/polyfills.ts"],
"exclude": ["node_modules", "platforms", "e2e"]
}

Please accept these terms

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the request in authenticationservice.ts and compare it with the Android completion path in @nativescript/core/http/http-request/index.android.js. Reproduce the POST against the stated http://10.0.2.2:4001/api/Login/Login endpoint, then determine whether the request completes without the reported unexpected end-of-stream error and add a focused regression test if the failure is reproducible.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, angular, typescript
Domain
api, mobile, networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.