-1

Any POST request to the wp rest api yields 404 responses, yet when switched to GET everything works fine.

The react component's method to handle a form submit with fetch:

handleFormSubmit(){
    event.preventDefault();
    const data = new FormData(event.target);

    fetch('sfg/wp-json/sfg/v1/login', {
     method : 'POST',
     body: data
    })
    .then( (res) => {
        console.log(res);
    } );

}

The register route function:

  register_rest_route( 'sfg/v1', '/login/', array(
    'methods' => 'POST',
    'callback' => 'json_login'
    ));

The callback:

function json_login(){

    $credentials = array();
    $credentials['user_name'] = $_POST['username'];
    $credentials['password'] = $_POST['password'];

    $status = wp_signon($credentials, false);

    return $status;
}

App is sending the request from a different port - 8081 rather than 8080.

Ozzy
  • 105
  • 10

1 Answers1

0

According to this URL. Can you try adding index.php after your project url.

  • Hi, when answering questions, it helps to show some context in what is in the link to a question you included to the question and its the solution. Otherwise, mark the question as a duplicate so it redirects to the question linked. – Dean Meehan Dec 31 '18 at 15:03