Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用angular 5 http.post()通过rest端点获取数据_Http_Http Post_Httpclient_Angular5 - Fatal编程技术网

使用angular 5 http.post()通过rest端点获取数据

使用angular 5 http.post()通过rest端点获取数据,http,http-post,httpclient,angular5,Http,Http Post,Httpclient,Angular5,我有下面的代码,我在angular 5中使用http.post方法通过REST API使用这些代码 return this._http.post(this.basePath,null, { headers: this.myHeaders, params: { transaction_id : "22" } , observe: 'response', responseType: 'json' }) .

我有下面的代码,我在angular 5中使用http.post方法通过REST API使用这些代码

return this._http.post(this.basePath,null, {
      headers: this.myHeaders,
      params: {
        transaction_id : "22"
      } ,
      observe: 'response',
      responseType: 'json'
    })
      .catch(this._errorHandler);
我可以使用http.get成功地获取数据,但使用post时出现500个内部服务器错误


我可能遗漏了什么?

当您发送HTTP POST时,后端服务期望得到什么?当前您正在发送一个空正文,这很可能是HTTP 500内部服务器错误的原因


仅仅因为您可以发出HTTP GET请求,并不总是意味着您可以对同一URL发出HTTP POST请求。帖子通常需要一些描述。如果POST不受支持,您可能希望后端服务返回一个不受支持的HTTP 406方法,但这取决于后端服务的编写情况。

我只需将参数作为POST方法主体选项的一部分进行传递,如下所示

let bodyParams = {transaction_id : "22"};

return this._http.post(this.basePath,bodyParams , {
          headers: this.myHeaders,,
          observe: 'response',
          responseType: 'json'
        })
          .catch(this._errorHandler);

它只需要我已传递的transaction_id参数。如果您将其作为查询参数传递,它是否需要在主体中?服务器需要什么编码/mime类型-表单还是json?