0

The requests appear to be sent to the wrong host (not entirely sure which host they're being sent to as that response can be sent by 4 different servers).

Chrome returns the right JSON response:

Chrome returns the valid JSON

Paw's NSURLConnection library too :

enter image description here

But the default Paw HTTP Library returns a 404 Not Found :

enter image description here

Micha Mazaheri
  • 3,481
  • 1
  • 21
  • 26

1 Answers1

0

You have actually 2 local servers listening on port 8000, one listens only IPv6 connections (note: it's the default for PHP apps) and another one listening for IPv4 connections.

When you connect to "localhost" you don't specify which IP protocol you want to use, and it sounds like most clients (including Chrome, ASIHTTPRequest and NSURLConnection in Paw) choose to connect to the IPv6 first. Whereas the Paw HTTP Library chooses to connect to IPv4 (we made that choice as IPv4 is still widely used, and wanted to avoid bugs as much as possible).

So when you run your main web app specifying localhost:8000 the server (PHP in your case) actually listens to [::1]:8000 (which is the IPv6 equivalent to 127.0.0.1:8000), and I guess your other server listens to the actual IPv4 127.0.0.1:8000. Chrome and the other libraries connect to [::1]:8000 (IPv6) and get your main PHP application, whereas "Paw HTTP Library" connect to 127.0.0.1:8000 (IPv4) that hits your other server, which returns the 404 we can see in the video.

What you need to do is to specify the actual IP instead of localhost. Use http://[::1]:8000/plans to connect to your main app that listens for IPv6.

Micha Mazaheri
  • 3,481
  • 1
  • 21
  • 26
  • Instead of avoiding a bug, you _introduced_ a bug. You should be connecting to IPv6 first, via the Happy Eyeballs algorithm. – Michael Hampton May 01 '15 at 02:43
  • Thanks @MichaelHampton, the Happy Eyeballs algorithm is definitively the answer. I don't have a deep knowledge of IP networking, and I believe it should be solved at the TCP networking level, so I added an issue on the repo of the library Paw is using https://github.com/robbiehanson/CocoaAsyncSocket/issues/315 – Micha Mazaheri May 01 '15 at 11:25