IONIC JSON REST API到WP REST API:请求对象为空

时间:2019-01-15 12:04:25

标签: ionic3 wordpress-rest-api

我的WP Request对象出现问题。 我创建了一个具有自定义终结点的Wordress插件:

add_action( 'rest_api_init', function () {
  register_rest_route( 'aplugin/v1', '/signup', array(
    'methods' => 'POST',
    'callback' => 'signup',
  ) );
} );

具有功能注册:

function signup( $request_data ) {

  write_log($request_data);

  }

我将此离子代码称为此API端点:

  post(endpoint: string, body: string, reqOpts?: any) {
    //var headers = new Headers();
    let headers = new Headers(
      {
        'Content-Type' : 'application/json'
      });
      let options = new RequestOptions({ headers: headers });

      let data = JSON.stringify({
        cardToken: 10,
        amount: 500
      });

    console.log("postjson body : " + body + "      endpoint : " + endpoint );
      console.log("postjson url : " + this.url + '/' + endpoint);
    return this.http.post(this.url + '/' + endpoint,  data , options);
  }

我可以呼叫端点(我的响应为200 http),但是我无法捕获请求参数。 WP Rest Request对象始终为空。

有人想帮我做这些事吗?

谢谢您的帮助。

0 个答案:

没有答案