I'm using this piece of code to access a url with beta 1
let config = NSURLSessionConfiguration.defaultSessionConfiguration()
let userPasswordString = "hroman:javierA17"
let userPasswordData = userPasswordString.dataUsingEncoding(NSUTF8StringEncoding)
let base64EncodedCredential = userPasswordData!.base64EncodedStringWithOptions(nil)
let authString = "Basic \(base64EncodedCredential)"
config.HTTPAdditionalHeaders = ["Authorization" : authString]
let session = NSURLSession(configuration: config)
var running = false
let url = NSURL(string: "http:/
let task = session.dataTaskWithURL(url!) {
(let data, let response, let error) in
if let httpResponse = response as? NSHTTPURLResponse {
let dataString = NSString(data: data!, encoding: NSUTF8StringEncoding)
print(dataString)
}
running = false
}
running = true
task.resume()
while running {
print("waiting...")
sleep(1)
}
I changed a few things and it doesn't work
let config = NSURLSessionConfiguration.defaultSessionConfiguration()
let userPasswordString = "hroman:javierA17"
let userPasswordData = userPasswordString.dataUsingEncoding(NSUTF8StringEncoding)
let base64EncodedCredential = userPasswordData!.base64EncodedStringWithOptions(NSDataBase64EncodingOptions(rawValue:0))
let authString = "Basic \(base64EncodedCredential)"
config.HTTPAdditionalHeaders = ["Authorization" : authString]
let session = NSURLSession(configuration: config)
var running = false
let url = NSURL(string: "http:/
let task = session.dataTaskWithURL(url!) {
(let data, let response, let error) in
if let httpResponse = response as? NSHTTPURLResponse {
let dataString = NSString(data: data!, encoding: NSUTF8StringEncoding)
print(dataString)
}
running = false
}
running = true
task.resume()
while running {
print("waiting...")
sleep(1)
}
I included the parameter NSAllowsArbitraryLoads on the info.plist for both cases.
What does this result mean? It's a problem of iOS 9?
What’s happening here is that iOS 9 delivers explicit authentication challenges (
NSURLAuthenticationMethodHTTPBasic
and
NSURLAuthenticationMethodHTTPDigest
) rather than the meta challenge that older systems used (
NSURLAuthenticationMethodDefault
). I was in a hurry so I just wrote code to handle the latter. Line 26 of my code should look like this:
if [NSURLAuthenticationMethodDefault, NSURLAuthenticationMethodHTTPBasic, NSURLAuthenticationMethodHTTPDigest].contains(challenge.protectionSpace.authenticationMethod) {
Unfortunately I can’t test what happens from there because the server now rejects the previous password:
$ curl -u hroman:javierA17 -is http://apps.solu4b.com/beepinservice/BeepInDataService.svc | head -1
HTTP/1.1 401 Unauthorized
Share and Enjoy
—
Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"