Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode Charles (HTTP Proxy) doesn't capture localhost traffic

I'm attempting to inspect http (non-SSL) traffic using XCode 6.1 and iOS Simulator 8.1 using Charles and my localhost apache server.

I've got Charles working correctly, but it only captures traffic when I use my local network IP address: 192.168.1.X as the target host for requests in iOS.

I've tried the other suggestions from the Charles article here, but none work except for the local network IP address.

"Why not just use the local network IP?", you ask?. Well, I'd like to avoid YASCE (yet another source control exception). You see, my source code has this in networking section:

#if DEBUG
    var API_HOST = "http://localhost"
#else
    var API_HOST = "https://website.com"
#endif

I'd like to avoid forcing every developer on the team to constantly make special considerations to avoid checking in their own personal IP address every time they are committing to source control.

Is there another way that I can convince the iOS simulator to pass http://localhost through Charles, or is there a better way to handle environment-specific settings with a development team?

like image 780
Albert Bori Avatar asked Nov 26 '14 23:11

Albert Bori


1 Answers

Use localhost.charlesproxy.com instead of localhost. That's setup on the charlesproxy.com DNS to point to 127.0.0.1, and always will. And because it's not literally localhost it should bypass the OS's hardwired logic for localhost.

It is also possible to use local.charles, but only if Charles is actually running and you're using it as your proxy. So I prefer the localhost.charlesproxy.com solution.

I'll update that FAQ too.

like image 184
Karl von Randow Avatar answered Oct 03 '22 02:10

Karl von Randow