我有一個Ionic 2
應用程序調用Spring Boot
API將推送通知發送到其他設備。該API使用HTTPS進行配置。HTTPS請求僅在iOS上失敗,Ionic 2
該API POST
請求的一切工作除了iOS
。
服務器上的我的SSL證書是自簽名的(也許就是這樣?)。
作品上:
- 離子服務
- 的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("https://<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
}
春季啓動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的安全性問題,但我不知道。
試試這個 - http://uncaughterror.com/programming/ionic3/preflight- response-issue-with-ionic3-app-on-ios-build-only-resolved/ –