the*_*het 6 api https spring-boot ionic2
我有一个Ionic 2
应用程序调用Spring Boot
API将推送通知发送到其他设备.API使用HTTPS配置.
API POST
请求适用于除外的 所有内容iOS
.
我在服务器上的SSL证书是自签名的(可能就是这样吗?).
适用于:
这是请求:
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("https://<some-url>",
body, { headers: headers }
).subscribe((response) => {
console.log("HTTPS RESPONSE");
console.log(response);
}, function(error) {
console.log("HTTPS ERROR");
console.log(error);
});
}
Run Code Online (Sandbox Code Playgroud)
标题响应如下:
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");
Run Code Online (Sandbox Code Playgroud)
并收到此错误:
{
"_body":
{"isTrusted":true},
"status":0,"ok":false,
"statusText":"",
"headers":{},
"type":3,
"url":null
}
Run Code Online (Sandbox Code Playgroud)
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);
}
Run Code Online (Sandbox Code Playgroud)
我假设它有iOS安全问题,但我不知道.
我认为你的假设是正确的——iOS 安全问题。在 iOS 中,有一种称为应用程序传输安全性的东西,默认情况下不允许通过 HTTP 进行连接以及使用自签名证书进行连接。
你必须添加
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
Run Code Online (Sandbox Code Playgroud)
到Info.plist
您的项目的 ,以允许您的自签名流量。
请参阅此答案以及以下链接以获取更多信息。
http://blog.ionic.io/preparing-for-ios-9/
https://gist.github.com/mlynch/284699d676fe9ed0abfa
归档时间: |
|
查看次数: |
7931 次 |
最近记录: |