JS:错误状态:URL的响应:200 null

时间:2018-07-31 08:25:42

标签: typescript ssl https nativescript

使用https时出现问题。

我尝试了以下代码:

 public output(): Observable<Item> {
    let headers = new Headers();
    headers.append('Content-Type', 'application/x-www-form-urlencoded');
    return this.http.get("https://xx.xxx.xx.xx:4433/login", {
      headers: headers
    })
      .pipe(map((response: Response) => {
        console.log('response', response)
        let res = response.json();
        if (res.StatusCode === 1) {
        } else {
          return new Item('');
        }
      }));
  }

此代码在她的console.log('response', response)部分中显示

JS:错误,状态:200,URL:空

你能问我任何想法吗?

constructor(private http: Http) { }更改为constructor(private http: HttpClient) { }

显示此错误:

JS: ERROR {
JS:   "headers": {
JS:     "normalizedNames": {},
JS:     "lazyUpdate": null,
JS:     "headers": {}
JS:   },
JS:   "status": 0,
JS:   "statusText": "Unknown Error",
JS:   "url": null,
JS:   "ok": false,
JS:   "name": "HttpErrorResponse",
JS:   "message": "Http failure response for (unknown url): 0 Unknown Error",
JS:   "error": {
JS:     "originalStack": "Error: javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.\n    at new ZoneAwareError (file:///data/data/org.nativescript.smartglass/files/app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:1298:33)\n    at onRequestComplete (file:///data/data/org.nativescript.smartglass/files/app/tns_modules/tns-core-modules/http/http-request/http-request.js:45:34)\n    at Object.onComplete (file:///data/data/org.nativescript.smartglass/files/app/tns_modules/tns-core-modules/http/http-request/http-request.js:37:13)",
JS:     "zoneAwareStack": "Error: javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorE...

导入:

   import { Injectable , NgZone } from "@angular/core";
    import { Item } from "./item";
    import 'rxjs/operators';
    import { Observable } from 'rxjs';
    import { map } from 'rxjs/operators';
    import { Http, Headers, Response } from '@angular/http';
    import { HttpClient} from "@angular/common/http";

0 个答案:

没有答案