ios - 尝试访问 API 时收到错误响应

标签 ios swift

我尝试使用 almofire 将设备 token 和设备详细信息发布到 Web 服务。但我收到如下回复

UserInfo={NSUnderlyingError=0x7fba3a590e50 {错误域=kCFErrorDomainCFNetwork Code=-1022“(null)”},NSErrorFailingURLStringKey=http://----/register , NSErrorFailingURLKey= http://---/register , NSLocalizedDescription=无法加载资源,因为应用程序传输安全策略要求使用安全连接。

在 Objective c 中,我尝试将所有值设置为 httpHeader,在 swift 中我使用了以下代码..

let params = ["notification_token":deviceToken,"device_identifier":deviceIdentifier,"advertising_identifier":"","model":deviceModel,"os":deviceOS,"os_version":deviceOSVersion,"app_version":deviceAppVersion]

let jsonData = try! NSJSONSerialization.dataWithJSONObject(params, options: [])

request(.POST, urlString, parameters: params,encoding:.JSON).responseJSON
                {
                    response in

                    if let JSON = response.result.value
                    {
                        // print("A JSON Result :\(JSON)")
                        delegate.API_CALLBACK_RegisterApp!(JSON as! NSDictionary)
                    }
                    else
                    {
                        delegate.API_CALLBACK_Error(0,errorMessage: response.result.error!.description)
                    }
            }

请帮助我..

最佳答案

您应该禁用应用程序传输安全性。

您必须在 .plist 文件中的 NSAppTransportSecurity 字典下将 NSAllowsArbitraryLoads 键设置为 YES。希望这有帮助!

enter image description here

关于ios - 尝试访问 API 时收到错误响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36125410/

相关文章:

ios - 位置管理器 :didRangeBeacons not detect the same beacon two times

ios - 如何将带有类名称的字符串转换为类类型本身?

iphone - Objective-C:更改来自单独类的图像

iphone - 使用 ASIHTTPRequest 或 NSURLConnection 将 authlogic 与 iPhone 客户端结合使用

facebook - 将社交媒体页面链接到我的应用程序中的按钮

ios - 在 iOS 中用新的 Storyboard 替换当前的 Storyboard

xcode - 查找数组的位置

ios - 使用 "PhoneGap Build"提交到 App Store 构建的 PhoneGap 应用程序

ios - AFHTTPRequestOperation 取消请求

ios - 当我尝试在 Firebase 数据库中插入日期作为键时崩溃