我对棱角非常陌生。我正在将发布请求从angular7发送到nodejs后端服务器,但没有任何反应,并在控制台中收到此错误:
net :: ERR_CONNECTION_REFUSED和消息:“ http失败响应为 http://localhost:4000/business/add:0未知错误”名称: “ HttpErrorResponse”
服务文件
export class BusinessService {
uri = 'http://localhost:4000/business';
constructor(private http: HttpClient) { }
addBusiness(person_name, business_name, business_gst_number) {
const obj = {
person_name: person_name,
business_name: business_name,
business_gst_number: business_gst_number
};
this.http.post(`${this.uri}/add`,obj)
.subscribe(res => console.log('Done'));
}
}
Node.js后端:
app.use('/business', businessRoute);
businessRoutes.route('/add').post( function(req, res){
console.log('hello');
let business = new Business(req.body);
business.save()
.then(business => {
res.status(200).json({'business': 'business in added sucessfully'});
}).catch(err => {
res.status(400).send('Unable to save to database');
console.log(err);
});
});