如何使用 httpclient post 方法将数据传递给 api

How to pass data to api using httpclient post method

我正在尝试使用 httpclient post 方法将数据传递给 api,但是在 api 中只传递了空数组

insert_data(input){
this.httpClient.post('http://localhost/tasker/api/index.php/insert_users', {
        data:input,
        tt:'tt'
      }).subscribe();

  }

输入数据可用

api是这样的

public function insert_users(){
    $input=$this->input->post();
    print_r($input);
}

尝试将您的代码更改为此

insert_data(input){
    const httpOptions = {
      headers: new HttpHeaders({
        'Content-Type':  'application/json'
      })
    };

    return this.httpClient.post('http://localhost/tasker/api/index.php/insert_users', 
          {
            data:input,
            tt:'tt'
          }, httpOptions);

      }
}

Post 方法不需要订阅。您必须订阅您的电话服务

    return this.insertDataService.inputData.subscribe();

如果还有问题请告诉我