问题
I wish to make a post request to a remote site but so that it updates remote site with data from database. I succeeded in getting the data using get request from database of current site but am unable to create a callback function for the post request. This is my code
function register_custom_route(){
register_rest_route( 'silentblast-dashboard/v1', '/getsetting/(?P<id>\d+)', array(
array(
'methods' => 'GET',
'callback' => 'retrieve_settings_data',
),
array(
'methods' => 'POST',
'callback' => 'update_settings_data',
)
));
}
function retrieve_settings_data(){
$out = get_option( 'buddysettings');
return $out;
}
function update_settings_data( $posts ){
//How to build this code to make post requests to remote site
}
来源:https://stackoverflow.com/questions/40929020/post-request-to-custom-end-point