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 … Read more