2015-09-24 52 views
10

​​3210應用傳輸安全性已阻止明文HTTP資源

我使用Socket.IO庫中迅速,我不斷收到此錯誤:

App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file.

當我試圖發送一個HTTP請求。根據官方的蘋果文檔,我將密鑰添加到了plist,但它沒有幫助。

+0

可能重複[交通運輸安全射門被明文HTTP](http://stackoverflow.com/questions/31254725/transport-security-has-blocked-a-cleartext- http) – brainray

+0

@ william-kinaan請不要在問題中添加不相關的標籤。這個問題與Swift無關,但與iOS相關。謝謝。 – Moritz

回答

24

你需要糾正這樣的:

enter image description here

爲了更方便,這是在info.plist中正確的XML

<key>NSAppTransportSecurity</key> 
    <dict> 
     <key>NSExceptionDomains</key> 
     <dict> 
      <key>localhost</key> 
      <dict> 
       <key>NSIncludesSubdomains</key> 
       <true/> 
       <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key> 
       <true/> 
       <key>NSTemporaryExceptionMinimumTLSVersion</key> 
       <string>TLSv1.1</string> 
      </dict> 
     </dict> 
    </dict> 

localhost更改爲您的實際服務器

Check the table for NSAppTransportSecurity options

如果你想與任何域的所有通信,你可以這樣做:

<key>NSAppTransportSecurity</key> 
    <dict> 
     <key>NSAllowsArbitraryLoads</key> 
     <true/> 
    </dict> 

但是,你應該使用最新的只是在發展階段。

+0

我做了完全相同的事情,現在我得到了這個: 由於App Transport Security不安全,App Transport Security阻止了明文HTTP(http://)資源加載。臨時例外可以通過您的應用程序的Info.plist文件進行配置。 請幫忙.. –

+0

我完全是XCode的新手。我有7.3,所以我看到相同的變量名稱**,除了**,它們在名稱中沒有* NS *。所以這個解決方案爲我工作! – ebichuhamster

4

我在截圖中看到錯誤的鍵和錯字。這是一個工作示例:

screen

+0

感謝您的修復!我無法從graph.facebook.com域下載Facebook個人資料信息,直到我添加NSExceptionAllowsInsecureHTTPLoads異常。現在按預期工作。乾杯! –

6

解決此問題的另一種方法是我使用NSAllowsArbitraryLoads密鑰在默認情況下禁用App Transport Security。因此,任何不包含在NSExceptionDomains詞典中的域名(或者根本不包括NSExceptionDomains)都不會受到App Transport Security的約束。

enter image description here

+0

每個人都給出了相同的答案,只有這一個,唯一的工作!謝謝:) – emotality

+0

我有XCode 7.1.1,我無法找到這個選項 – tccpg288

4

Xcode項目 - >去的info.plist並點擊+按鈕,然後添加程序(App交通運輸安全設置)展開,允許任意裝入設置YES。 謝謝

1

我正在使用xCode 8.2。這是一個有點不同,但編輯您需要在App Transport Security Settings行添加這兩個項目的plist文件...:

Allow Arbitrary LoadsAllow Arbitrary Loads in Web Content ...並給他們倆的關鍵YES

它爲我工作,希望爲你工作,併爲我的英語感到抱歉。

enter image description here

enter image description here

相關問題