簡體   English   中英

Http請求在ionic服務上起作用,但在“ ionic cordova run android --device”上不起作用

[英]Http request working on ionic serve but doesn't work on “ionic cordova run android --device”

我正在使用Ionic本機HTTP發出服務器請求。 該服務器托管在AWS上,並且api已啟動並正在運行(已由郵遞員驗證)。

當我做離子服務時,請求會通過並起作用,但是當我嘗試在設備上運行它時,它將無法工作。 經檢查,我得到“ net :: ERR_CLEARTEXT_NOT_PERMITTED”,並且帖子以OPTIONS的形式發送

錯誤HttpErrorResponse {標頭:HttpHeaders,狀態:0,statusText:“未知錯誤”,網址:“ http://18.220.143.133/api/login ”,確定:false,…}

已經嘗試添加到config.xml

login(user: User): Observable<AuthResponse> {
return this.httpClient.post('http://18.220.143.133/api/login', user, {
  headers: new HttpHeaders().set('Content-Type', 'application/json'),
}).pipe(
  tap(async (res: AuthResponse) => {

    if (res.success == true) {

      await this.storage.set('user',res.user);

       await this.storage.set('ACCESS_TOKEN', res.token);
      this.authSubject.next(true);
    }

  })
);

}

我希望http請求也能通過移動設備處理。

它與API調用的CORS有關。 可能會有所幫助。 另外,由於您使用的是Angular HTTP請求,請在此處檢查來自angular的HTTP請求將使用OPTIONS方法而不是POST發送

我也發生了同樣的事情,直到在config.xml文件中添加了:

<preference name = "android-targetSdkVersion" value = "27" />

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM