在尝试以angular编码的x-www-form-urle的post方法时,获取错误消息400(错误请求)



我在postposter中尝试了post-menthod,可以发送带有名称和描述的邮件,但在服务中我无法发送。有人知道我的服务有什么问题吗?

postCreateMember(name, desc): Observable<any> {
let httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/x-www-form-urlencoded'
}),
withCredentials: true
};
const nssUrl = this.baseUrl + 'Members';
var body = {
Name: name,
Description: desc
};
return this.http.post<HttpRequestResponse>(nssUrl, body, httpOptions).pipe(
map(
(data) => {
return data;
},
(error) => console.log(error)
)
);
}

像这样尝试

import { Component, VERSION, OnInit } from '@angular/core';
import { Observable } from 'rxjs';
import { HttpHeaders, HttpClient } from '@angular/common/http';
import { map } from 'rxjs/operators';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent implements OnInit {
name = 'Angular ' + VERSION.major;
baseUrl = 'https://angular-ivy-xpuugc.stackblitz.io/';
constructor(private http: HttpClient) {}
postCreateMember(name, desc) {
let httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/x-www-form-urlencoded'
})
, withCredentials: true
};
const nssUrl = this.baseUrl + 'Members';
const body = new FormData();
body.append('Name', name);
body.append('Description', desc);
return this.http.post(nssUrl, body, httpOptions ).pipe(
map(
data => {
return data;
},
error => console.log(error)
)
);
} 
ngOnInit() {
this.postCreateMember('test','text').subscribe((response:any)=> {
console.log(response);
});
}
}

相关内容

  • 没有找到相关文章

最新更新