vendredi 31 juillet 2015

iOS NSMutableURLRequest Authorization Header

I am having trouble accessing an API call and I think it has something to do with the authorization header. I am using AlamoFire and printing out the token so I know it is valid.

var URLRequest: NSURLRequest {
    let URL = NSURL(string: Router.baseURLString + path)!
    let mutableURLRequest = NSMutableURLRequest(URL: URL)
    mutableURLRequest.HTTPMethod = method.rawValue

    println(Router.OAuthToken)
    if let token = Router.OAuthToken {
        mutableURLRequest.setValue("Token token=\(token)", forHTTPHeaderField: "Authorization")
    }

    println(mutableURLRequest)

    switch self {
    default:
        return mutableURLRequest
    }
}

This is what the documentation says and it works right in the terminal with the auth token:

curl -H "Authorization: Token token=<ACCESS_TOKEN>" http://ift.tt/1M1QOoI

Here is the error I'm receiving:

Optional(Error Domain=com.alamofire.error Code=-1 "The operation couldn’t be completed. (com.alamofire.error error -1.)")

Aucun commentaire:

Enregistrer un commentaire