Reputation: 10002
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?
Upvotes: 7
Views: 4042
Reputation: 484
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.
Upvotes: 3
Reputation: 37339
I am using my hostname instead of localhost. To get your hostname simply type hostname
in the terminal and then change the URL to "http://your-host-name"
Upvotes: 1
Reputation: 10002
I found an acceptable work-around. It involves editing your hosts file to create an alias for localhost. Each developer will have to do this on his/her dev machine, but it should be smooth sailing after that.
Run echo '127.0.0.1 local.website.com' >> "/etc/hosts"
and then change your host config code to something like this:
#if DEBUG
var API_HOST = "http://local.website.com"
#else
var API_HOST = "https://website.com"
#endif
Upvotes: 2
Reputation: 239
Same problem happened to me. Using my computer's name instead of "localhost" solved my problem, and enable to display it on Charles. For example, my computer's name is "sukwon" and I solved it by using "http://sukwon.local" instead of using "http://localhost"
Upvotes: 0