Qualcuno ha un'idea su come configurare le intestazioni HTTP con NSURLRequest in Swift? Ho l'autenticazione impostato sul mio server e necessita solo di un token passato ad esso, ma sto avendo impostando l'intestazione guaiIntestazioni HTTP con NSURLRequest in swift
il mio codice:
func getLatestData() {
var loggedInUsersNumber:String = SharingManager.sharedInstance.userID
var usersDataPoint:String = StormDataPoint + loggedInUsersNumber
activityIND.hidden = false
activityIND.startAnimating()
let request = NSURLRequest(URL: NSURL(string: usersDataPoint)!)
let tokenString = SharingManager.sharedInstance.authToken
//request.setValue("Token " + tokenString, forKey: "Authorization")
let urlSession = NSURLSession.sharedSession()
let task = urlSession.dataTaskWithRequest(request, completionHandler: {
(data, response, error) -> Void in
if let error = error {
print(error)
return }
ho creato una proprietà "tokenString" per essere il token per passare nell'intestazione e sulla riga successiva in cui ho commentato. request.setvalue - L'ho inserito e ho ricevuto un errore sulla melodia di "impossibile sovrascrivere il tipo di dati". Tutte le mie ricerche mostrano l'aiuto dell'obiettivo C. C'è un modo migliore per provare a passare un'intestazione?
[docs Apple] (https://developer.apple.com/documentation/foundation/nsmutableurlrequest) avvertono che il campo 'AUTORIZZAZIONE non deve essere impostato utilizzando questi metodi. È giusto? –