Skip to content
This repository was archived by the owner on Sep 24, 2018. It is now read-only.
This repository was archived by the owner on Sep 24, 2018. It is now read-only.

Unable to post to remote url #2945

Description

@djouonang

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 '
';

}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions