How can I use CURLOPT_USERPWD in wp_remote_post?

Use the Authorization header. Example:

$auth = base64_encode( $username . ':' . $password );

$args = [
    'headers' => [
        'Authorization' => "Basic $auth"
    ],
    'body'    => $body,
];      

$response      = wp_remote_post( $url, $args );
$response_body = wp_remote_retrieve_body( $response );

Leave a Comment