13

Before anything, I want to list out the posts that I have read and tried implementing the answers from (avoiding duplicates):

I am working on an SDK and I have created some UI tests. I am trying not to connect to the backend systems and mocking them via a stubserver that runs in the local machine whilst testing. All requests must go to this server.

I have created an dummy app that will never be submitted to the App Store. Through this app I plan to test the SDK's screens. I followed the posts and articles above and included an exception to have insecure connections to my localhost server into the dummy app's Info.plist file. It looks like the following:

<key>NSAppTransportSecurity</key>
    <dict>
        <key>NSExceptionDomains</key>
        <dict>
            <key>localhost</key>
            <dict>
                <key>NSIncludesSubdomains</key>
                <true/>
                <key>NSExceptionAllowsInsecureHTTPLoads</key>
                <true/>
            </dict>
        </dict>
        <key>NSAllowsArbitraryLoadsInWebContent</key>
        <true/>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
    </dict>

Yes I have allowed all kinds of exceptions. The network response does not complain about the app not having the exception for insecure connections to localhost but simply returns the following:

[Result]: FAILURE: Error Domain=NSURLErrorDomain Code=-1004 "Could not connect to the server." UserInfo={NSUnderlyingError=0x170248940 {Error Domain=kCFErrorDomainCFNetwork Code=-1004 "(null)" UserInfo={_kCFStreamErrorCodeKey=61, _kCFStreamErrorDomainKey=1}}, NSErrorFailingURLStringKey=http://localhost:7878/endpoint, NSErrorFailingURLKey=http://localhost:7878/endpoint, _kCFStreamErrorDomainKey=1, _kCFStreamErrorCodeKey=61, NSLocalizedDescription=Could not connect to the server.}
[Timeline]: Timeline: { "Request Start Time": 510144201.835, "Initial Response Time": 510144201.860, "Request Completed Time": 510144201.860, "Serialization Completed Time": 510144201.860, "Latency": 0.025 secs, "Request Duration": 0.025 secs, "Serialization Duration": 0.000 secs, "Total Duration": 0.025 secs }

I look at the server logs and nothing is reported. I therefore assume that it does not hit the server entirely.

Any help would be appreciated. :)

Thanks

Community
  • 1
  • 1
a.ajwani
  • 868
  • 1
  • 8
  • 21
  • check server URL once again. – Hardik Shekhat Mar 02 '17 at 10:59
  • I have copied and pasted the url that errors and just curled it and it works – a.ajwani Mar 02 '17 at 11:00
  • 3
    On what device are you running this? Simulator or an actual device? I think the issue is due to the _localhost_ server endpoint. Have you tried pointing it to a cloud server? – Teffi Mar 02 '17 at 11:01
  • Oh shoot! @Teffi you nailed it, was running on a device didn't look at the target device! – a.ajwani Mar 02 '17 at 11:04
  • 1
    if the iphone and the computer are on the same wifi. and if you use apache. then all you need is to get the computer local ip address and change localhost with that ip address –  Nov 05 '18 at 02:49
  • https://stackoverflow.com/questions/19482164/how-can-i-access-localhost-from-another-computer-in-the-same-network – Rauan Feb 22 '19 at 18:07

2 Answers2

36

As @Teffi pointed out in the comments I was running the test on a device that did not have access to my localhost server running on my local machine.

a.ajwani
  • 868
  • 1
  • 8
  • 21
0

Resolved for me

I have also faced this same issue and now fixed. When I stopped and started my aws instance the connection string have changed. You can find this changed connection string on your aws after clicking on connect button. Then replace old url by this new one to your AppDelegateo class (already have one)

Hope got it.

Arif Hosain
  • 140
  • 1
  • 5