首页 > 代码库 > 网络请求失败原因及解决

网络请求失败原因及解决

Q1.出现

"resource load since it is insecure"

"The resource could not be loaded because the App Transport Security policy requires the use of a secure connection"

这两段错误提示

解决方式:

①选中info.plist

②选中Information Property List后面的加号?

③弹框中选择App Transport Security Settings

④点击App Transport Security Settings前的箭头,再点击加号?

⑤弹框仅有三个选项,选择Allow Arbitrary Loads

⑥将Allow Arbitrary Loads后的NO改成YES即可

 

Q2.出现

"Request failed: unacceptable content-type: text/html"错误提示

是由于JSon序列化有不支持的格式,即text/html

解决方式:可通过闭包的形式往单例中添加格式支持

1     static let shareInstance: NetworkTools = {2         let tools = NetworkTools()3         tools.responseSerializer.acceptableContentTypes?.insert("text/html")4         return tools5     }()

 

网络请求失败原因及解决