Post request to custom end point

只愿长相守 提交于 2019-12-12 04:27:55

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!