網絡請求失敗原因及解決


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 tools
5     }()

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM