我無法從服務器獲取有關用戶的信息。基本訪問驗證
它我使用這些:
用戶: 「[email protected]」
通: 「1234ABCD」
主機: 「www.host.com」
https://[email protected]:[email protected]/user.xml
NSData * returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:&響應錯誤:& errorServer];
在錯誤我根據維基百科https://en.wikipedia.org/wiki/Basic_access_authentication 網址模板的文章有這樣的
Error Domain=NSURLErrorDomain Code=-1200 "An SSL error has occurred and a secure connection to the server cannot be made." UserInfo={_kCFStreamErrorCodeKey=-9847, NSLocalizedRecoverySuggestion=Would you like to connect to the server anyway?, NSUnderlyingError=0x7f9c7be02f50 {Error Domain=kCFErrorDomainCFNetwork Code=-1200 "An SSL error has occurred and a secure connection to the server cannot be made." UserInfo={NSErrorFailingURLStringKey=https://[email protected]:[email protected]/user.xml, NSLocalizedRecoverySuggestion=Would you like to connect to the server anyway?, _kCFNetworkCFStreamSSLErrorOriginalValue=-9847, _kCFStreamPropertySSLClientCertificateState=0, NSLocalizedDescription=An SSL error has occurred and a secure connection to the server cannot be made., _kCFStreamErrorDomainKey=3, NSErrorFailingURLKey=https://[email protected]:[email protected]/user.xml, _kCFStreamErrorCodeKey=-9847}}, NSLocalizedDescription=An SSL error has occurred and a secure connection to the server cannot be made., NSErrorFailingURLKey=https://[email protected]:[email protected]/user.xml, NSErrorFailingURLStringKey=https://[email protected]:[email protected]/user.xml, _kCFStreamErrorDomainKey=3}
看起來不錯
URL encoding A client may avoid a login prompt when accessing a basic access authentication by prepending username:[email protected] to the hostname in the url. For example, the following would access the page index.html at the web site www.example.com with the secure HTTPS protocol and provide the username Aladdin and the password OpenSesame credentials via basic authorization:
https://Aladdin:[email protected]/index.html
是的,我設置 「應用交通運輸安全設置」
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
我做錯了什麼?
你不能編碼在URL中usernam和密碼。在這種情況下,您需要設置基本身份驗證標頭 – Paulw11
服務器給我錯誤響應(默認數據) – Vit
顯示代碼設置標頭的位置 – Paulw11