1
votes

My REST is beautifully working, i can get the result from the link: "172.18.52.78/bniforum451/wp-json/wp/v2/posts" and all combination REST link.

But, i always get "No route was found matching the URL and request method" when i call link : 172.18.52.78/bniforum451/wp-json/jwt-auth/v1/token.

eventhough when i call (172.18.52.78/bniforum451/wp-json/jwt-auth/v1/) i can get the result :

{
  "namespace": "jwt-auth/v1",
  "routes": {
    "/jwt-auth/v1": {
      "namespace": "jwt-auth/v1",
      "methods": [
        "GET"
      ],
      "endpoints": [
        {
          "methods": [
            "GET"
          ],
          "args": {
            "namespace": {
              "required": false,
              "default": "jwt-auth/v1"
            },
            "context": {
              "required": false,
              "default": "view"
            }
          }
        }
      ],
      "_links": {
        "self": "172.18.52.78/bniforum451/wp-json/jwt-auth/v1"
      }
    },
    "/jwt-auth/v1/token": {
      "namespace": "jwt-auth/v1",
      "methods": [
        "POST"
      ],
      "endpoints": [
        {
          "methods": [
            "POST"
          ],
          "args": []
        }
      ],
      "_links": {
        "self": "172.18.52.78/bniforum451/wp-json/jwt-auth/v1/token"
      }
    },
    "/jwt-auth/v1/token/validate": {
      "namespace": "jwt-auth/v1",
      "methods": [
        "POST"
      ],
      "endpoints": [
        {
          "methods": [
            "POST"
          ],
          "args": []
        }
      ],
      "_links": {
        "self": "172.18.52.78/bniforum451/wp-json/jwt-auth/v1/token/validate"
      }
    }
  },
  "_links": {
    "up": [
      {
        "href": "172.18.52.78/bniforum451/wp-json/"
      }
    ]
  }
}

What is the best practice to solve my problem?

I'am using :

  • Wordpress Version 4.5.3
  • XAMPP v3.2.1 (Local Server Windows 7)
  • PHP Version 5.6.14
  • WP REST API (Version 2.0-beta13)
  • JWT Authentication for WP-API (Version 1.2.0 )

Thanks

Gema

  • i erase the "http" from the "172.18.52.78" link because i dont have 10 reputation yet :D
1
In my case the problem was that I used an HTTP URL, but the webserver was configured to redirect HTTP to HTTPS. Changing HTTP to HTTPS in the request URL fixed the problem.Marvin Klar

1 Answers

0
votes

Try watching this video I created: https://youtu.be/Mp7T7x1oxDk

I think you're performing a GET request on /bniforum451/wp-json/jwt-auth/v1/token when it should be POST. You should also pass username and password in the request body.

The reason /bniforum451/wp-json/jwt-auth/v1/ works is because it is meant to respond to GET requests instead of POST. It only gives you the API info.

If you take a look at the output you got from your successful call, it tells you right there what methods the /token endpoint accepts.

"/jwt-auth/v1/token": {
  "namespace": "jwt-auth/v1",
  "methods": [
    "POST"
  ],
  "endpoints": [
    {
      "methods": [
        "POST"
      ],
      "args": []
    }
  ],
  "_links": {
    "self": "172.18.52.78/bniforum451/wp-json/jwt-auth/v1/token"
  }
},