GMGM Ответов: 0

Я должен войти на веб-сервер с https с логином и паролем. Я всегда получаю ошибку 401. Где, по-твоему, я ошибаюсь?


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()


Что я уже пробовал:

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

Richard MacCutchan

Эта ошибка означает, что сервер не распознает ваши учетные данные. Поговорите с владельцами сайта.

0 Ответов