简体   繁体   English

如何在 angular 的 post 请求中发送这种类型的正文

[英]How to send this type of body in post request in angular

{ "name": "kiran", "email": "sai123@gmail.com", "phone_number": "123456789", "type": "individual", "billing": { "address":{ "line1":"1234 Main Street", "city":"San Francisco", "state":"CA", "postal_code":"94111", "country": "US" } } } { "name": "kiran", "email": "sai123@gmail.com", "phone_number": "123456789", "type": "individual", "billing": { "address":{ "line1" :"1234 Main Street", "city":"San Francisco", "state":"CA", "postal_code":"94111", "country": "US" } } }

You can simply make an object of json.您可以简单地制作一个 json 的 object。

like

var obj =   { "name": "kiran", "email": "sai123@gmail.com", "phone_number": "123456789", "type": "individual", "billing": { "address":{ "line1":"1234 Main Street", "city":"San Francisco", "state":"CA", "postal_code":"94111", "country": "US" } } }

Then然后

Post(obj:any)  {
          return this.http.post('apiUrlhere',{obj});
          }

and call it using并使用

 this.Post(ObjHere)
 .subscribe(
  data => { 
   //result inside data
   });

Where http is其中http

private http: HttpClient私人 http:HttpClient

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

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