NativeScript / NativeScript/NativeScript
Nativescript with Angular - Http call gives error - 'unexpected end of stream on com.android.okhttp.Address@1d8e59ae'
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- TypeScript
- Estrellas
- 25.7k
- Forks
- 1.7k
- Merge medio
- 1 d 5 h
- PR fusionados (30 d)
- 35
Descripción
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
- I have searched the existing issues as well as StackOverflow and this has not been posted before
- This is a bug report
- I agree to follow this project's Code of Conduct
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza con la solicitud en authenticationservice.ts y compárala con la ruta de finalización de Android en @nativescript/core/http/http-request/index.android.js. Reproduce el POST contra el endpoint indicado http://10.0.2.2:4001/api/Login/Login y determina después si la solicitud se completa sin el error notificado „unexpected end-of-stream“. Añade una prueba de regresión específica si el fallo se puede reproducir.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- android, angular, typescript
- Área
- api, mobile, networking
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Necesita aclaración
- Aptitud para principiantes
- 25/100