Click here to Skip to main content
15,881,559 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
let test =  WDatiGlobali.LeaderWatch_Sito + "/dati_generali/PROGRAMMI/LEADER_WATCH_INVIO_MENU.aspx?CODICE_UTENTE_APP=LEADER_WATCH_ATTIVAZIONE_WEB_SERVICE&PASSWORD_UTENTE_APP=LEADER_WATCH_APP_PASSWORD&CODICE_UTENTE=" + login! + "&CODICE_PASSWORD=" + pass! + "&MOMENTO_ULTIMO_AGGIORNAMENTO_MENU=TEST_CONNESSIONE&DISPOSITIVO=" + urlwithPercentEscapes +
        "&FUSO="  + urlstring


        let credenziali:  URLCredential = URLCredential(user: login!, password: pass!, persistence: URLCredential.Persistence.forSession)
        let url: URL = URL(string: test)!
        let protectionSpace = URLProtectionSpace(host: url.host!, port: 443, protocol: url.scheme, realm: "leaderwatch", authenticationMethod:  NSURLAuthenticationMethodHTTPBasic)
        let credentialStorage = URLCredentialStorage.shared
        credentialStorage.set(credenziali, for: protectionSpace)
        let sessionConfiguration = URLSessionConfiguration.default
        sessionConfiguration.urlCredentialStorage = credentialStorage
        let session = URLSession(configuration: sessionConfiguration)
        let task = session.dataTask(with: url) { (data, response, error) in
        if error != nil
        {
        print("error")
        print(error!.localizedDescription)
        }
        else
        {
        do
        {
        print("Error: \(response)")
        print("hjhjhjhjhjhjhjhjhjhjh")
        print("Error: \(data)")
        }
        catch
        {
        print("Error: \(error)")
        }
        }
        }
        task.resume()


What I have tried:

I have also tried in other ways with request in POST, but I always get the same error.
All the examples I found always give 401 error
Posted
Comments
Richard MacCutchan 28-Aug-18 5:37am    
That error means that the server does not recognise your credentials. Talk to the website owners.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900