呼叫休息服务没有捕获IOS中的HTTP响应代码401

时间:2017-10-04 20:18:08

标签: ios iphone rest http ionic3

我在通过iOS调用其他服务时遇到了麻烦,因为在Android中一切正常。当我通过登录名和密码无效时,服务器返回状态401(通过postman / Android / ionic服务),现在当我通过iOS进行调用时,它不会返回任何内容(我把它识别并显示返回的服务器上的日志)它没有收到任何类似订阅返回或http.get捕获的内容,因此我无法捕获错误并进行处理。

总结API的调用是由iOS进行的,但是当订阅中的错误在返回401时没有落入catch中。但是当我没有Internet时,它处于捕获声音状态0。 / p>

IOS(FAIL)的回复不回归:

Response in IOS (FAIL) not return catch

在控制台xCode上打印错误:

CredStore - performQuery - Error copying matching creds.  Error=-25300, 
query={
    class = inet;
    "m_Limit" = "m_LimitAll";
    ptcl = htps;
    "r_Attributes" = 1;
    sdmn = "api.site.com.br";
    srvr = "api.site.com.br";
    sync = syna;
}

android中的响应(OK)返回catch:

Response in android (OK) return catch

PROCESS:

我正在调用静态的API,作为类型GET并在base64授权中作为参数传递登录名和密码。 当我使进程发送正确的登录名和密码时,它返回状态200并带有有效令牌。但是当发送无效的登录名和密码时,服务器返回状态401(这没关系,我做了邮递员测试)。

包装:

        "@angular/common": "4.1.2",
        "@angular/compiler": "4.1.2",
        "@angular/compiler-cli": "4.1.2",
        "@angular/core": "4.1.2",
        "@angular/forms": "4.1.2",
        "@angular/http": "4.1.2",
        "@angular/platform-browser": "4.1.2",
        "@angular/platform-browser-dynamic": "4.1.2",
        "@ionic-native/core": "3.7.0",
        "@ionic-native/in-app-browser": "^3.10.3",
        "@ionic-native/onesignal": "^4.3.0",
        "@ionic-native/splash-screen": "3.7.0",
        "@ionic-native/status-bar": "3.7.0",
        "@ionic/storage": "2.0.1",
        "cordova-android": "^6.2.3",
        "cordova-ios": "^4.4.0",
        "cordova-plugin-console": "^1.0.7",
        "cordova-plugin-device": "^1.1.6",
        "cordova-plugin-inappbrowser": "^1.7.1",
        "cordova-plugin-splashscreen": "^4.0.3",
        "cordova-plugin-statusbar": "^2.2.3",
        "cordova-plugin-whitelist": "^1.3.2",
        "ionic-angular": "3.3.0",
        "ionic-plugin-keyboard": "^2.2.1",
        "ionicons": "3.0.0",
        "onesignal-cordova-plugin": "^2.2.1",
        "rxjs": "5.1.1",
        "sw-toolbox": "3.6.0",
        "zone.js": "0.8.10"

CODE:

getToken(login, senha): Promise<{}> {
    return new Promise((resolve, reject) => {
      let options = new RequestOptions({
        headers: new Headers({
          'Authorization': 'Basic ' + btoa(login + ":" + senha),
          "cache-control": "no-cache"
        })
      });
      this.http.get("https://subdominio.site.com.br/api/login", options)
        .map(res => res.json())
        .subscribe(data => {
          console.error("Subscribe OK -> " + data);
          resolve(data);
        }, error => {
          console.error("Subscribe error ->" + error);
          reject(error);
        });
    });
  }

离子信息:

image3

有没有人遇到过这个问题?

0 个答案:

没有答案