HomeiOS Developmentios - How to connect with localhost api?

ios – How to connect with localhost api?


That is my code:

class MovieService: ObservableObject {
    func getAllMovies() {
        guard let url = URL(string:"http://localhost:7056/api/Motion pictures/GetMovies") else {
            return;
        }
        var request = URLRequest(url: url)
        request.httpMethod = "POST"
        request.setValue("utility/json",forHTTPHeaderField: "Content material-Sort")
        let physique:[String: AnyHashable] = [
            "page":1,
            "pageSize":25,
            "genreId":0,
            "yearId":0,
            "seachValue":"",
        ]
        request.httpBody = strive? JSONSerialization.information(withJSONObject: physique)
        let process = URLSession.shared.dataTask(with: request) { (information, _, error) in
            guard let information = information, error == nil else {
                return
            }
            do {
                let response = strive JSONSerialization.jsonObject(with: information, choices: [])
                print(response)
            } catch {
                print(error)
            }
        }
        process.resume()
    }
}

That is the error:

2023-03-18 01:26:44.695576+0100 WhatchMoviesOnline[46545:3820350] [] nw_protocol_get_quic_image_block_invoke dlopen libquic failed
2023-03-18 01:26:44.696844+0100 WhatchMoviesOnline[46545:3820350] [connection] nw_socket_handle_socket_event [C1.1:2] Socket SO_ERROR [61: Connection refused]
2023-03-18 01:26:44.700470+0100 WhatchMoviesOnline[46545:3820350] [connection] nw_socket_handle_socket_event [C1.2:2] Socket SO_ERROR [61: Connection refused]
2023-03-18 01:26:44.701635+0100 WhatchMoviesOnline[46545:3820350] Connection 1: acquired failure notification
2023-03-18 01:26:44.702876+0100 WhatchMoviesOnline[46545:3820350] Connection 1: failed to attach 1:61, motive -1
2023-03-18 01:26:44.703112+0100 WhatchMoviesOnline[46545:3820350] Connection 1: encountered error(1:61)
2023-03-18 01:26:44.706704+0100 WhatchMoviesOnline[46545:3820350] Job <44020F8F-D4B7-477E-9304-96F513A0A80E>.<1> HTTP load failed, 0/0 bytes (error code: -1004 [1:61])
2023-03-18 01:26:44.725204+0100 WhatchMoviesOnline[46545:3820356] Job <44020F8F-D4B7-477E-9304-96F513A0A80E>.<1> completed with error [-1004] Error Area=NSURLErrorDomain Code=-1004 "Couldn't connect with the server." UserInfo={_kCFStreamErrorCodeKey=61, NSUnderlyingError=0x60000351c9c0 {Error Area=kCFErrorDomainCFNetwork Code=-1004 "(null)" UserInfo={_kCFStreamErrorCodeKey=61, _kCFStreamErrorDomainKey=
"LocalDataTask <44020F8F-D4B7-477E-9304-96F513A0A80E>.<1>"
), NSLocalizedDescription=Couldn't connect with the server., NSErrorFailingURLStringKey=http://localhost:7056/api/Motion pictures/GetMovies, NSErrorFailingURLKey=http://localhost:7056/api/Motion pictures/GetMovies, _kCFStreamErrorDomainKey=1}

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments