Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
348 views
in Technique[技术] by (71.8m points)

api - Angular http.post() Syntax Issues with body

This is the Postman Screenshot by which I'm getting response successfully! And I want to fetch data in angular but the http.post() syntax issue occurs.

See here

const bodyCode = { seat_hell: "765", helloo: "1611255600" };

export class DashDataTable22Component implements  OnInit {

  data =[]; 
  
  constructor(private http:Http) {
    this.http.post('http://199.100.155.771/xyzza/', JSON.stringify(bodyCode)).subscribe(
      data =>{
        this.data = data.json(); 

      }
    )
  }
question from:https://stackoverflow.com/questions/65846120/angular-http-post-syntax-issues-with-body

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Use bodyCode without stringify.

this.http.post('http://199.100.155.771/xyzza/', bodyCode)
.subscribe(data => {
    this.data = data.json(); 
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...