Alamofire: iOS 11 localhost http access

Created on 30 Sep 2017  路  7Comments  路  Source: Alamofire/Alamofire

What did you do?

Updated to Xcode 9 with the latest Alamofire pod, and sending GET request to http://localhost:8080/storys

What did you expect to happen?

200 response with normal payload as it always does.

What happened instead?

Alamofire request gets error:

Error: Optional(Error Domain=NSURLErrorDomain Code=-1004 "Could not connect to the server." UserInfo={NSUnderlyingError=0x1c0255db0 {Error Domain=kCFErrorDomainCFNetwork Code=-1004 "(null)" UserInfo={_kCFStreamErrorCodeKey=61, _kCFStreamErrorDomainKey=1}}, NSErrorFailingURLStringKey=http://localhost:8080/storys, NSErrorFailingURLKey=http://localhost:8080/storys, _kCFStreamErrorDomainKey=1, _kCFStreamErrorCodeKey=61, NSLocalizedDescription=Could not connect to the server.})

Note that:
1) https request works for my real server
2) I verified curl & postman & Chrome works on the localhost url, and added ATS keys to info.plist:

<key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
        <key>NSAllowsLocalNetworking</key>
        <true/>
        <key>NSExceptionDomains</key>
        <dict>
            <key>localhost</key>
            <dict>
                <key>NSExceptionAllowsInsecureHTTPLoads</key>
                <true/>
                <key>NSExceptionRequiresForwardSecrecy</key>
                <false/>
                <key>NSIncludesSubdomains</key>
                <true/>
                <!-- Optional: Specify minimum TLS version -->
                <key>NSTemporaryExceptionMinimumTLSVersion</key>
                <string>TLSv1.1</string>
                <key>NSRequiresCertificateTransparency</key>
                <false/>
            </dict>
        </dict>
    </dict>

Could the iOS 11 deprecations of some cyphers hashes and protocols?
https://stackoverflow.com/a/46481875/1032900

Alamofire Environment

Alamofire version: 4.0.0
Xcode version: 9.0
Swift version: 4
Platform(s) running Alamofire: iOS 11
macOS version running Xcode: 10.12.6

support

Most helpful comment

@hyouuu @jshier @speedoholic @jshier Just put your local IP instead of localhost in url .
e.g. http://192.168.1.34:3000/
That should be work....

All 7 comments

Strange. That error is very generic but I'm pretty sure it's not an ATS or other issue like that. Instead it's more likely the server isn't running at all. Is this a server that's running locally on device? Or are you connecting to a server on the local network? I asked, because cURL, Postman, and Chrome wouldn't work with a server on a local device. Please verify that's the server is actually running.

While this is unlikely to be an Alamofire issue, I won't close the issue yet, as I'm interested in seeing whether local server behavior has changed in iOS 11.

For some reason it works today o.O I did update macOS to High Sierra and not sure whether there was a bug with Xcode 9 on Sierra - also please note I was running on simulator not a local device, and the server was definitely running when I reported.

Thanks for the reply and hopefully the above information provides some insights.

@jshier Thanks for the response to this query. I also faced a similar problem and learned that it was a server issue.
@hyouuu Thanks for making your post well detailed.

@hyouuu @jshier @speedoholic @jshier Just put your local IP instead of localhost in url .
e.g. http://192.168.1.34:3000/
That should be work....

Best way to resolve this is using ngrok

Thanks @pandeyshivang

Thanks @pandeyshivang

Welcome @peimanrn 馃檹

Was this page helpful?
0 / 5 - 0 ratings