Angular 正文始终为空或角格式错误

Angular 正文始终为空或角格式错误,angular,axios,Angular,Axios,我有个问题要解决。我不明白哪里是我的错。我已经遵循了教程,我尝试了stackoverflow中的解决方案,但没有任何解决方案是有效的 所以,我想用body发送Post,它应该是JSON(我用postman尝试了我的端点,这很完美)。 每次我发送它时,它总是空的或格式错误 这是我的密码 const instance = axios.create({ baseURL: 'https://us-central1-roamx-6c177.cloudfunctions.net',

我有个问题要解决。我不明白哪里是我的错。我已经遵循了教程,我尝试了stackoverflow中的解决方案,但没有任何解决方案是有效的

所以,我想用body发送Post,它应该是JSON(我用postman尝试了我的端点,这很完美)。 每次我发送它时,它总是空的或格式错误

这是我的密码

const instance = axios.create({
      baseURL: 'https://us-central1-roamx-6c177.cloudfunctions.net',
      timeout: 1000,
      headers: {'Content-Type': 'application/json', 'Access-Control-Allow-Origin' : 'http://localhost:4200'}
    });

instance({
        method: 'post',
        url: '/SBpaymidrove',
        data: {a: "b", c: 2}
      }).then(response => console.log(response));
如果我跑,身体是空的

但如果我把标题改为

application/x-www-form-urlencoded
它变成这样(登录firebase)

我不明白,我试过这些方法。 和 我也尝试从angular使用http/common,但结果相同

两者都不起作用。请帮忙

编辑 这里,如果我从angular使用http

this.header = new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded');

this.http.post<DetailTransaction>('https://us-central1-***********.cloudfunctions.net/SBpaymidrove',
     {a: "b", c: 2}, {headers: this.header, withCredentials: true})
     .subscribe(
     data  => {
     console.log("POST Request is successful ", data);
     },
     error  => {
     console.log("Error", error);
     }
);
this.header=new-HttpHeaders().set('Content-Type','application/x-www-form-urlencoded');
this.http.post('https://us-central1-***********.cloudfunctions.net/SBpaymidrove',
{a:“b”,c:2},{headers:this.header,withCredentials:true})
.订阅(
数据=>{
console.log(“POST请求成功”,数据);
},
错误=>{
console.log(“错误”,Error);
}
);

您使用axios而不是Angular http客户端的原因是什么?只是好奇:)@KurtHamilton不不,我是angular http客户端的忠实粉丝,它太完美了。就我而言,我已经尝试过了,但失败了,所以如果它能解决我的问题,我就尝试了其他库。但这并没有解决。你想我也使用anguar http发布吗?我会提供的。我会说有0.01%的错误是Angular
HttpClient
在这里:)你应该添加你用
HttpClient
尝试过的内容,以及你在Postman中提交的内容。这应该突出问题所在is@KurtHamilton您好,我已经添加了它们。先生,请帮帮我。谢谢。您还可以说明什么是
detailTrx
和什么是
baseUrl
吗?您使用axios而不是Angular http客户端的原因是什么?只是好奇:)@KurtHamilton不不,我是angular http客户端的忠实粉丝,它太完美了。就我而言,我已经尝试过了,但失败了,所以如果它能解决我的问题,我就尝试了其他库。但这并没有解决。你想我也使用anguar http发布吗?我会提供的。我会说有0.01%的错误是Angular
HttpClient
在这里:)你应该添加你用
HttpClient
尝试过的内容,以及你在Postman中提交的内容。这应该突出问题所在is@KurtHamilton您好,我已经添加了它们。先生,请帮帮我。谢谢。您还可以展示一下什么是
detailTrx
,什么是
baseUrl
this.header = new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded');

this.http.post<DetailTransaction>('https://us-central1-***********.cloudfunctions.net/SBpaymidrove',
     {a: "b", c: 2}, {headers: this.header, withCredentials: true})
     .subscribe(
     data  => {
     console.log("POST Request is successful ", data);
     },
     error  => {
     console.log("Error", error);
     }
);