HTTPS请求仅在iOS Ionic 2上失败

编程入门 行业动态 更新时间:2024-10-26 12:34:19
本文介绍了HTTPS请求仅在iOS Ionic 2上失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个Ionic 2应用程序,该应用程序调用Spring Boot API将推送通知发送到其他设备.该API已配置为HTTPS.

I have an Ionic 2 application that calls a Spring Boot API to send push notifications to other devices. The API is configured with HTTPS.

API POST请求适用于除 iOS以外的所有内容.

The API POST request works on everything except iOS.

我在服务器上的SSL证书是自签名的(也许就是这样).

My SSL certificate on the server is self signed (maybe that's it?).

适用于:

  • 离子服务
  • Android
  • 邮递员
  • 卷曲

这是请求:

public sendNotificationRequest(title: string, action: string, name: string, tokens: any, notifications: boolean) { // Check if user turned off notifications if(!notifications) { return; } let headers = new Headers({'Content-Type': 'application/json'}); headers.append('Authorization', 'Basic ' + btoa(this.username_decrypted + ':' + this.password_decrypted)); let body = this.formObj(tokens, title, action, name); console.log(body); this.http.post("<some-url>", body, { headers: headers } ).subscribe((response) => { console.log("HTTPS RESPONSE"); console.log(response); }, function(error) { console.log("HTTPS ERROR"); console.log(error); }); }

标头响应如下:

response.setHeader("Access-Control-Allow-Origin", "*"); response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE"); response.setHeader("Access-Control-Max-Age", "3600"); response.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization");

并且收到此错误:

{ "_body": {"isTrusted":true}, "status":0,"ok":false, "statusText":"", "headers":{}, "type":3, "url":null }

Spring Boot API:

Spring Boot API:

@CrossOrigin @RequestMapping(value="/notifications", method=RequestMethod.POST, consumes=MediaType.APPLICATION_JSON_VALUE, produces=MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<NotificationParent> sendNotifications(@RequestBody NotificationParent objs) { ... return new ResponseEntity<NotificationParent>(objs, HttpStatus.OK); }

我认为这是iOS的安全问题,但我不知道.

I am assuming its an iOS security issue, but I have no idea.

推荐答案

我认为您的假设是正确的-一个iOS安全问题.在iOS中,有一种称为应用程序传输安全性"的应用程序,默认情况下不允许通过HTTP进行连接以及使用自签名证书进行连接.

I think your assumption is correct-- an iOS security issue. In iOS there is something called App Transport Security that disallows, by default, connections over HTTP and connections with self-signed certificates.

您必须添加

<key>NSAppTransportSecurity</key> <dict> <key>NSAllowsArbitraryLoads</key> <true/> </dict>

转到项目的Info.plist,以允许您进行自签名访问.

to the Info.plist of your project to allow your self-signed traffic.

有关更多信息,请参见此答案以及以下链接.

See this answer as well as the below links for more info.

blog.ionic.io/preparing-for-ios- 9/

gist.github/mlynch/284699d676fe9ed0abfa

developer.apple/library/prerelease/content/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html#//apple_ref/doc/uid/TP40009251-SW33

更多推荐

HTTPS请求仅在iOS Ionic 2上失败

本文发布于:2023-11-14 11:27:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1587088.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:HTTPS   iOS   Ionic

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!