EngineeringBasic Authentication with the WordPress HTTP API
Basic Authentication (or BasicAuth) is not natively handled with the WordPress HTTP API.
Last reviewed
This page sits in the Engineering section of Ludicrous. It carries a publication date of August 10, 2010, and 2 pages on this domain share that year. The section is 9 pages deep.
The wording is the original. Where an old note was brief, it is still brief here.
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.
Below it are the closest entries by date, which is usually the fastest way back into whatever this page was part of. Where the original gave no figure, none has been supplied here.
From the original thread
2 replies2 replies were left on this page between 2010 and 2025, kept as they were written. The avatars, profile links and reply form of the software that collected them are not part of this archive, and the addresses readers pasted are kept as text rather than as links.
A reader
Hi John, Thanks for the link to Charles. Just had a play and it looks incredibly useful.
A reader
A year later, but still great info thanks dude. Sometimes wordpress drives me crazy.
