Cron and request with wp_remote_post
I have a problem with a plugin I'm working on, I have implemented a cron that 2 times a day makes a call to update the data, the call is made with the wp_remote_post function.
$response = wp_remote_post(
ENDPOINT,
array(
'method' = 'POST',
'headers' = array(
'Content-Type' = 'application/json; charset=utf-8',
'domainUrl' = get_site_url(),
),
'body' = wp_json_encode( $body ),
)
);
the problem is in the get_site_url()
function.
For a site that uses the https protocol, get_site_url()
returns the domain in https when the call is triggered from the frontend or wordpress hooks except cron, instead when get_site_url()
is triggered by the cron hook it returns http.
What may be causing this behavior and how I could fix it?
Thanks