这是我的代码
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Rx';
@Injectable()
export class LinkedinPageProvider {
constructor(public http: HttpClient) {
console.log('Hello LinkedinPageProvider Provider');
}
//posting facebook data ---------------------------------------
postFacebookData(fbData) {
alert(fbData.email);
let headers = new HttpHeaders();
//headers.append('Content-Type','application/json');
return this.http.post('http://192.168.0.100:3000/api/facebookuser',fbData,{headers: headers})
}
}
app.js
文件
app.use(cors());
app.use(methodOverride());
app.use(methodOverride('X-HTTP-Method-Override'));
//app.use(express.session({ secret: 'keyboard dog' }));
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Methods", "GET,HEAD,OPTIONS,POST,PUT");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization");
next();
});
const users = require('./routes/users');
app.use('/api',users);
这是路由js文件(users.js
)
router.post('/facebookuser', function(req,res) {
console.log('facebook request');
在我的节点js控制台中,我可以看到facebook request
。数据存储在数据库中,但在前端控制台(Chrome控制台)中引发错误
ERROR HttpErrorResponseerror:ProgressEventheaders: HttpHeadersmessage:“(失败的url)Http失败响应:0 未知错误“名称:” HttpErrorResponse“确定:错误状态:0statusText: “未知错误” URL:null__proto__:HttpResponseBase defaultErrorLogger @ vendor.js:1823 ErrorHandler.handleError @ vendor.js:1884
POST http://192.168.0.100:3000/api/facebookuser net::ERR_CONNECTION_REFUSED