Wie Einfügen von PHP-Curl-Funktion in WordPress. Ich habe diesen PHP-Code ausprobiert und es funktioniert wie erwartet. Wie man die gleiche Curl-Funktion in WordPress konvertiert.Wie Sie CURL in WordPress platzieren
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://api.bstcm.no/customer/-8/offers");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
$username = 'atrium',
$password = '3HnzkG2p',
curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password)
));
$response = curl_exec($ch);
curl_close($ch);
$details = json_decode($response, TRUE);
?>
Ich versuchte dies:
<?php
$response = wp_remote_get('http://api.bstcm.no/customer/-8/offers', array(
'headers' => array(),
'body' => array('username' =>'atrium','password' => '3HnzkG2p')
)
);
if (is_wp_error($response)) {
$error_message = $response->get_error_message();
echo "Something went wrong: $error_message";
} else {
echo 'response:<pre>';
print_r($response);
echo '</pre>';
}
?>