I am trying to send data to remote url using the wp_remote_post. I did not set up any permission call back for the code but i get a 403 forbidden error when i click to send form with data to remote url.This is my code;
function register_custom_route(){ register_rest_route( 'silentblast-dashboard/v1', '/getsetting/', array(
array(
'methods' => 'GET',
'callback' => 'retrieve_settings_data',
),
array(
'methods' => 'POST',
'callback' => 'update_settings_data',
)
));
}
function update_settings_data( $request ){
$out = update_option( 'buddy_settings', $request );
$out = get_option( 'buddy_settings' );
return $out ;
}
$remote_url = 'http://localhost/wordpress/wp-json/silentblast- dashboard/v1/getsetting/';
$posts = (array) $posts;
$args = array (
'method' => 'POST',
'timeout' => 45,
'redirection' => 5,
'httpversion' => '1.0',
'blocking' => true,
'body' => $posts,
'cookies' => array ()
);
$request = wp_remote_post( $remote_url, $args );
if ( is_wp_error( $request ) ) { $error_message = $request->get_error_message(); echo sprintf( 'Something went wrong: %1s
', $error_message ); }
else {
//echo 'Response:
';
print_r($request);
echo '
';
}
Why do i get a 403 error when posting data to remote url with code below;
$remote_url = 'http://localhost/wordpress/wp-json/silentblast-dashboard/v1/getsetting/';
$response = wp_remote_get( $url );
$posts = wp_remote_retrieve_body( $response );
$posts = json_decode($posts);
$posts = (array) $posts;
$args = array (
'method' => 'POST',
'timeout' => 45,
'redirection' => 5,
'httpversion' => '1.0',
'blocking' => true,
'body' => $posts,
'cookies' => array ()
);
$request = wp_remote_post( $remote_url, $args );
if ( is_wp_error( $request ) ) { $error_message = $request->get_error_message(); echo sprintf( 'Something went wrong: %1s
', $error_message ); }
else {
//echo 'Response:
';
print_r($request);
echo '
';
}
I am trying to send data to remote url using the wp_remote_post. I did not set up any permission call back for the code but i get a 403 forbidden error when i click to send form with data to remote url.This is my code;
function register_custom_route(){ register_rest_route( 'silentblast-dashboard/v1', '/getsetting/', array(
array(
'methods' => 'GET',
'callback' => 'retrieve_settings_data',
),
array(
'methods' => 'POST',
'callback' => 'update_settings_data',
)
));
}
function update_settings_data( $request ){
$out = update_option( 'buddy_settings', $request );
$out = get_option( 'buddy_settings' );
return $out ;
}
$remote_url = 'http://localhost/wordpress/wp-json/silentblast- dashboard/v1/getsetting/';
$posts = (array) $posts;
$args = array (
$request = wp_remote_post( $remote_url, $args );
if ( is_wp_error( $request ) ) { $error_message = $request->get_error_message(); echo sprintf( 'Something went wrong: %1s
', $error_message ); }
else {
//echo 'Response:
';}
Why do i get a 403 error when posting data to remote url with code below;
$remote_url = 'http://localhost/wordpress/wp-json/silentblast-dashboard/v1/getsetting/';
$response = wp_remote_get( $url );
$posts = wp_remote_retrieve_body( $response );
$posts = json_decode($posts);
$posts = (array) $posts;
$args = array (
'method' => 'POST',
'timeout' => 45,
'redirection' => 5,
'httpversion' => '1.0',
'blocking' => true,
'body' => $posts,
'cookies' => array ()
);
$request = wp_remote_post( $remote_url, $args );
if ( is_wp_error( $request ) ) { $error_message = $request->get_error_message(); echo sprintf( 'Something went wrong: %1s
', $error_message ); }
else {
//echo 'Response:
';}