1
如何使用基本身份驗證在json中獲取數據?我想從我的示例代碼中顯示字典中的數據,該怎麼做?在swift中獲取基本身份驗證的請求3
let username = "user"
let password = "pass"
let loginString = String(format: "%@:%@", username, password)
let loginData = loginString.data(using: String.Encoding.utf8)!
let base64LoginString = loginData.base64EncodedString()
// create the request
let url = URL(string: "http://xxx.xxx.xxx.com:111/customer")!
var request = URLRequest(url: url)
request.httpMethod = "GET"
request.setValue("Basic \(base64LoginString)", forHTTPHeaderField: "Authorization")
// fire off the request
// make sure your class conforms to NSURLConnectionDelegate
let urlConnection = NSURLConnection(request: request, delegate: self)
值是零 – ibmot
你得到的是零響應?打印時,響應對象的外觀如何? – Wazza