简体   繁体   English

angular2 - HTTP post请求参数为null

[英]angular2 - HTTP post request parameters are null

i am trying to call a HTTP post method like this. 我试图像这样调用HTTP post方法。 It is working fine in local development and have issues in production. 它在当地开发中运作良好,并且在生产中存在问题。

let URL = url;
let body = { tenantId, branchId };
let headers = new Headers({ 'Content-Type': 'application/json' });
let options = new RequestOptions({ headers: headers });
return this._http.post(URL, body, options).map(res => res.json()).
  catch(error => Observable.throw(error.json().error || 'Server error'));

But when i get these parameters in the server side, the values are becoming null.What might be the reason? 但是当我在服务器端获取这些参数时,值变为空。可能是什么原因? Help me on this. 帮助我。 Thanks 谢谢

The proble is with your body object. 问题在于你的身体对象。 It is not a valid object. 它不是有效的对象。

let body = { tenantId, branchId };

It should be something like: 它应该是这样的:

let body = { tenantId: 123, branchId: 123 }; . You are not assing any value to the object properties. 您没有为对象属性赋值。

You don't need to stringfy... 你不需要stringfy ......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM