Tag Archives: HTTP

Access Your Desktop Development Environment from Your Mobile Device

It’s really easy to get an iPhone, iPad or other iOS device to access a local web server running on your development machine. All you need is Charles Proxy running on your development machine (which you should have anyway, as it’s invaluable). Once that’s running:

Make sure your iOS device is connected to the same network as your development machine. Go into the Settings -> Wi-Fi menu on your iOS device and click the arrow next to your network. From there switch the HTTP proxy setting to manual and enter your development environment machine’s network IP address (eg. 192.168.0.4) as the server, and 8888 as the port (Charles’ default port unless you’ve changed it).

Voila. All your HTTP traffic from your iOS device will now route through Charles running on your desktop (Charles will prompt you to allow access first) and you’ll have access to your local development server. Awesome!

Aside: Android users, you’ve not got it as easy. There aren’t any HTTP proxy settings in Android (who said Android was an open platform?) so unless you’re willing to jailbreak your Android you’re out of luck. There may well be similar proxy settings for other mobile OSes. A quick Google will usually give you the answer.

Pro Tip: Are you still editing your hosts file in order to manage the host name mapping for sites on your development environment? Stop it. Just use the Tools -> DNS Spoofing menu in Charles and make life easier for yourself.

Basic Authentication with the WordPress HTTP API

Basic Authentication (or BasicAuth) is not natively handled with the WordPress HTTP API. This means when you’re using functions such as wp_remote_get() and wp_remote_post() there’s no immediately obvious way to send Basic Authentication headers with your request. It would be great to pass username and password parameters to these functions, but it’s not there.

Fear not though, it’s really easy. Here’s how:

$args = array(
'headers' => array(
'Authorization' => 'Basic ' . base64_encode( YOUR_USERNAME . ':' . YOUR_PASSWORD )
)
);
wp_remote_request( $url, $args );

That’s it. The correct authentication headers will then be sent with your request (after you’ve replaced YOUR_USERNAME and YOUR_PASSWORD with the obvious).

I’d like to give a quick shout out to my favourite HTTP monitor Charles Proxy. I use Charles almost daily when dealing with server-side HTTP requests and AJAX requests and it makes life much easier. I love it.