在WordPress可以使用wp_remote_get和wp_remote_post
GET請求,例如
$url = 'http://www.elitbuzzsms.com/app/smsapi/index.php?key=KEY&campaign=****&routeid=**&type=text&contacts=<NUMBER>&senderid=SMSMSG&msg=< Message Content >';
$response = wp_remote_get($url );
if(is_array($response)) {
$header = $response['headers']; // array of http header lines
$body = $response['body']; // use the content
}
POST請求例如
$response = wp_remote_post($url, array(
'method' => 'POST',
'timeout' => 45,
'redirection' => 5,
'httpversion' => '1.0',
'blocking' => true,
'headers' => array(),
'body' => array('username' => 'bob', 'password' => '1234xyz'),
'cookies' => array()
)
);
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>';
}
你有什麼迄今所做? –
我不知道如何在wordpress中使用API。我是新手。如果你能幫忙,我會很感謝 –