0
如何在WordPress中插入php curl函數。我已經試過這個PHP代碼,它按預期工作。如何在WordPress中轉換相同的捲曲功能。如何在wordpress中放置CURL
<?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);
?>
我嘗試這樣做:
<?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>';
}
?>