我有一个asp.net
后端服务。后端api从postman
正常工作
但从角度做同样的事情是行不通的。正文不会发送到服务器。我正在使用角7。
这是我的代码。
乳品服务
public addNewDairy(value) {
return this.http.post(this.apiUrl + "dairy", value)
.pipe(
map(success => success),
catchError(this.hes.handleError) // then handle the error
);
}
和组件
requestForRegistration(value) {
this.jqxLoader.open();
this.ds.addNewDairy(value).subscribe(res => {
this.jqxLoader.close();
this.message = "Requested for activation.";
this.notification.open();
}, error => {
console.log(error);
this.jqxLoader.close();
this.message = "Something went wrong please try again!";
this.notification.open();
});
}
204来自OPTIONS请求,浏览器将其作为跨域请求的一部分发送。一旦OPTIONS请求成功返回200,您的真实请求就会上升。 Postman不会发送OPTIONS请求,因为您将直接转到该实例中的API。您的Angular看起来很好 - 我会在您的asp.net后端验证已启用CORS - 请参阅此处https://docs.microsoft.com/en-us/aspnet/web-api/overview/security/enabling-cross-origin-requests-in-web-api#enable-cors。