您好我是Nativescript移动应用程序开发的新手,我想做的是我创建了一个应用程序,并希望将其连接到服务器以获取一些数据,我已经按照Nativescript Doc中的所有setps但无法连接到服务器。这些是我的代码请帮帮我。
app.module.ts
import { NgModule, NO_ERRORS_SCHEMA } from "@angular/core";
import { NativeScriptModule } from "nativescript-angular/nativescript.module";
import { NativeScriptRouterModule } from "nativescript-angular/router";
import { HttpClientModule } from "@angular/common/http";
import { NativeScriptHttpModule } from "nativescript-angular/http";
import { NativeScriptHttpClientModule } from "nativescript-angular/http-client";
import { AppComponent } from "./app.component";
import { navigatableComponents, routes } from './app-routing.module';
@NgModule({
declarations: [AppComponent, navigatableComponents],
bootstrap: [AppComponent],
imports: [
NativeScriptModule,
NativeScriptRouterModule,
NativeScriptRouterModule.forRoot(routes),
NativeScriptHttpClientModule,
HttpClientModule,
NativeScriptHttpModule
],
schemas: [NO_ERRORS_SCHEMA],
})
export class AppModule {}
login.component.ts
test() {
this.httpClient.get("http://localhost:60929/ApiTest/Data").subscribe(data => {
console.log(data)
})
}
我收到此错误
System.err: java.net.ConnectException: Connection refused
System.err: at java.net.PlainSocketImpl.socketConnect(Native Method)
System.err: at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:334)
System.err: at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:196)
System.err: at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:178)
System.err: at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:356)
System.err: at java.net.Socket.connect(Socket.java:586)
System.err: at com.android.okhttp.internal.Platform.connectSocket(Platform.java:113)
System.err: at com.android.okhttp.Connection.connectSocket(Connection.java:1432)
System.err: at com.android.okhttp.Connection.connect(Connection.java:1390)
System.err: at com.android.okhttp.Connection.connectAndSetOwner(Connection.java:1667)
System.err: at com.android.okhttp.OkHttpClient$1.connectAndSetOwner(OkHttpClient.java:133)
System.err: at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:466)
System.err: at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:371)
System.err: at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:503)
System.err: at com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:130)
System.err: at org.nativescript.widgets.Async$Http$HttpRequestTask.doInBackground(Async.java:543)
System.err: at org.nativescript.widgets.Async$Http$1.run(Async.java:482)
System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
System.err: at org.nativescript.widgets.Async$PriorityThreadFactory$1.run(Async.java:52)
System.err: at java.lang.Thread.run(Thread.java:762)
JS: ERROR Error: Uncaught (in promise): [object Object]
M真的很难坚持这个