POST 请求在 Ionic2 应用中的 IOS 上不起作用
POST requests not working on IOS in Ionic2 App
我遇到 HTTP 请求问题。在 Ionic View、浏览器和 Android 中一切正常,但在 IOS 上不工作。 GET 请求在 IOS 上也能正常工作。猜猜看,那是什么?
我可以为您提供更多信息,请告诉我您需要什么信息。这是我的 package.json:
"dependencies": {
"@angular/common": "2.2.1",
"@angular/compiler": "2.2.1",
"@angular/compiler-cli": "2.2.1",
"@angular/core": "2.2.1",
"@angular/forms": "2.2.1",
"@angular/http": "2.2.1",
"@angular/platform-browser": "2.2.1",
"@angular/platform-browser-dynamic": "2.2.1",
"@angular/platform-server": "2.2.1",
"@ionic/cloud-angular": "0.7.0",
"@ionic/storage": "1.1.7",
"@types/moment-timezone": "0.2.32",
"ionic-angular": "2.0.0-rc.4",
"ionic-native": "2.4.1",
"ionicons": "3.0.0",
"moment": "2.15.1",
"moment-timezone": "0.5.7",
"ng2-translate": "5.0.0",
"rxjs": "^5.0.0-beta.12",
"zone.js": "0.6.26"
},
"devDependencies": {
"@ionic/app-scripts": "^1.0.0",
"sw-toolbox": "^3.4.0",
"typescript": "2.0.9"
},
后端收到 post 请求的空白正文。这是我得到的结果:
ERROR: {"_body":"{\"error\":\"Sign up error\",\"message\":{\"first_name\":[\"First Name cannot be blank.\"],\"last_name\":[\"Last Name cannot be blank.\"],\"email\":[\"Email cannot be blank.\"],\"device_id\":[\"Device Id cannot be blank.\"]}}","status":422,"ok":false,"statusText":"Bad Request","headers":{"Content-Type":["application/json; charset=UTF-8"],"Pragma":["no-cache"]},"type":2,"url":"http://app.EDITED"}
有什么问题欢迎提问,感谢您的帮助!
更新:我们将后端移至 HTTPS,现在一切正常 :)
官方答案好像在这里:
Apple 只是决定强制使用 HTTPS。我怀疑 Cordova / Ionic 目前根本无法很好地处理这个问题(也就是没有抛出错误,没有记录等)
请记住,Safari 检查器将显示数据正在发送到服务器 - 这是不正确的所有发送的数据都被删除(整个主体)在 iOS 应用程序(我为此浪费了一天)。
正如 Dmytro Garastovych 所提到的,正确(也是唯一)的解决方案是转向 HTTPS
我遇到 HTTP 请求问题。在 Ionic View、浏览器和 Android 中一切正常,但在 IOS 上不工作。 GET 请求在 IOS 上也能正常工作。猜猜看,那是什么?
我可以为您提供更多信息,请告诉我您需要什么信息。这是我的 package.json:
"dependencies": {
"@angular/common": "2.2.1",
"@angular/compiler": "2.2.1",
"@angular/compiler-cli": "2.2.1",
"@angular/core": "2.2.1",
"@angular/forms": "2.2.1",
"@angular/http": "2.2.1",
"@angular/platform-browser": "2.2.1",
"@angular/platform-browser-dynamic": "2.2.1",
"@angular/platform-server": "2.2.1",
"@ionic/cloud-angular": "0.7.0",
"@ionic/storage": "1.1.7",
"@types/moment-timezone": "0.2.32",
"ionic-angular": "2.0.0-rc.4",
"ionic-native": "2.4.1",
"ionicons": "3.0.0",
"moment": "2.15.1",
"moment-timezone": "0.5.7",
"ng2-translate": "5.0.0",
"rxjs": "^5.0.0-beta.12",
"zone.js": "0.6.26"
},
"devDependencies": {
"@ionic/app-scripts": "^1.0.0",
"sw-toolbox": "^3.4.0",
"typescript": "2.0.9"
},
后端收到 post 请求的空白正文。这是我得到的结果:
ERROR: {"_body":"{\"error\":\"Sign up error\",\"message\":{\"first_name\":[\"First Name cannot be blank.\"],\"last_name\":[\"Last Name cannot be blank.\"],\"email\":[\"Email cannot be blank.\"],\"device_id\":[\"Device Id cannot be blank.\"]}}","status":422,"ok":false,"statusText":"Bad Request","headers":{"Content-Type":["application/json; charset=UTF-8"],"Pragma":["no-cache"]},"type":2,"url":"http://app.EDITED"}
有什么问题欢迎提问,感谢您的帮助!
更新:我们将后端移至 HTTPS,现在一切正常 :)
官方答案好像在这里:
Apple 只是决定强制使用 HTTPS。我怀疑 Cordova / Ionic 目前根本无法很好地处理这个问题(也就是没有抛出错误,没有记录等)
请记住,Safari 检查器将显示数据正在发送到服务器 - 这是不正确的所有发送的数据都被删除(整个主体)在 iOS 应用程序(我为此浪费了一天)。
正如 Dmytro Garastovych 所提到的,正确(也是唯一)的解决方案是转向 HTTPS