kean / Get

Web API client built using async/await
MIT License
937 stars 74 forks source link

Using HTTP instead of HTTPS #27

Closed aleguizzo closed 2 years ago

aleguizzo commented 2 years ago

Can I use HTTP instead of HTTPS? If I manually specify http:// it doesn't work and if I don't specify it it uses https. Code: @IBAction func backendDetails(_ sender: Any) { let client = APIClient(host: "http://\(hostname):\(port)") Task{ let result = try? await client.send(.get("/STOInfo/STOVersion")).value } } Result: 2022-04-09 16:11:17.499954+0200 ServiceTOOLS Control[1854:101545] Connection 0: encountered error(12:1) 2022-04-09 16:11:17.500943+0200 ServiceTOOLS Control[1854:101620] Task <758B7F50-2C4C-42E1-8D91-EDF251350051>.<1> HTTP load failed, 0/0 bytes (error code: -1000 [1:22]) 2022-04-09 16:11:17.508481+0200 ServiceTOOLS Control[1854:101620] Task <758B7F50-2C4C-42E1-8D91-EDF251350051>.<1> finished with error [-1000] Error Domain=NSURLErrorDomain Code=-1000 "bad URL" UserInfo={_kCFStreamErrorCodeKey=22, NSUnderlyingError=0x2804f12c0 {Error Domain=kCFErrorDomainCFNetwork Code=-1000 "(null)" UserInfo={_kCFStreamErrorCodeKey=22, _kCFStreamErrorDomainKey=1}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <758B7F50-2C4C-42E1-8D91-EDF251350051>.<1>, _NSURLErrorRelatedURLSessionTaskErrorKey=( "LocalDataTask <758B7F50-2C4C-42E1-8D91-EDF251350051>.<1>" ), NSLocalizedDescription=bad URL, NSErrorFailingURLStringKey=https://http%3a%2f%2f192.168.178.20%3a5704/STOInfo/STOVersion, NSErrorFailingURLKey=https://http%3a%2f%2f192.168.178.20%3a5704/STOInfo/STOVersion, _kCFStreamErrorDomainKey=1} Result without http:// : 2022-04-09 16:19:26.078668+0200 ServiceTOOLS Control[1912:103890] Connection 3: received failure notification 2022-04-09 16:19:26.078771+0200 ServiceTOOLS Control[1912:103890] Connection 3: failed to connect 12:8, reason -1 2022-04-09 16:19:26.078822+0200 ServiceTOOLS Control[1912:103890] Connection 3: encountered error(12:8) 2022-04-09 16:19:26.080123+0200 ServiceTOOLS Control[1912:103890] Task <E28CB0EE-1963-436A-9334-38F862483B88>.<1> HTTP load failed, 0/0 bytes (error code: -1003 [12:8]) 2022-04-09 16:19:26.084242+0200 ServiceTOOLS Control[1912:103890] Task <E28CB0EE-1963-436A-9334-38F862483B88>.<1> finished with error [-1003] Error Domain=NSURLErrorDomain Code=-1003 "A server with the specified hostname could not be found." UserInfo={_kCFStreamErrorCodeKey=8, NSUnderlyingError=0x2836f70c0 {Error Domain=kCFErrorDomainCFNetwork Code=-1003 "(null)" UserInfo={_NSURLErrorNWPathKey=satisfied (Path is satisfied), interface: en0, ipv4, dns, _kCFStreamErrorCodeKey=8, _kCFStreamErrorDomainKey=12}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <E28CB0EE-1963-436A-9334-38F862483B88>.<1>, _NSURLErrorRelatedURLSessionTaskErrorKey=( "LocalDataTask <E28CB0EE-1963-436A-9334-38F862483B88>.<1>" ), NSLocalizedDescription=A server with the specified hostname could not be found., NSErrorFailingURLStringKey=https://192.168.178.20%3a5704/STOInfo/STOVersion, NSErrorFailingURLKey=https://192.168.178.20%3a5704/STOInfo/STOVersion, _kCFStreamErrorDomainKey=12}

kean commented 2 years ago

You can use a new baseURL parameter in Get 0.7.0:

APIClient(baseURL: URL(string: "http://\(hostname):\(port)"))