Tag: angular2 http

angular2-rc1 http.post不能正常工作

我正在创build一个angular2应用程序,我在我的服务中使用http进行POST调用到mongoDB 。 当我第一次进行POST调用时,它工作正常,即条目插入到数据库正确,但是当我第二次发送数据时,它不被插入。 如果我第一次插入后重新加载页面,那么它的工作正常。 我做了一些debugging,发现在第二次请求时,我的req.body是空白的。 这是我的代码: page.service.ts savePage(page: Object) { this.headers.append('Content-Type', 'application/json'); let url = this.baseUrl+'/pm/pages/'; let data={}; data["data"]=page; console.log(data); //this is printing both times correctly //on second request data is blank where as it works correctly for first time return this.http.post(url, JSON.stringify(data),{headers: this.headers}) .map((res: Response) => res.json()).catch(this.handleError); } 这是我在节点服务中显示的req.body中的数据。 首要要求 : body:{ data:{ name: […]

Angular2和Node:Preflight的响应具有无效的HTTP状态码403

我有以下方法为angular2中的标头与{"Content-Type": "application/json",'Authorization':this.authToken} public allJobsStageWidget1= (): Observable<WidgetModel[]> => { let widget1Url= this._configuration.ServerWithApiUrl + 'getAllJobsStagesCount'; return this._http.get(widget1Url,new RequestOptions({ headers: new Headers({"Content-Type": "application/json",'Authorization':this.authToken}) })) .map((response: Response) => {console.log(response.json());response.json() }) .catch(this.handleError); } 在我的节点应用程序中,完成以下工作: app.use(function(req, res, next) { res.header('Access-Control-Allow-Credentials', true); res.header('Access-Control-Allow-Origin', '*'); res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS'); res.header('Access-Control-Allow-Headers', 'X-Requested-With, X-HTTP-Method-Override, Content-Type, Accept'); res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type,Authorization ,Accept'); next(); }); 当我发出一个GET请求,那么'XMLHttpRequest cannot load http://rest-0023:3000/api/getAllJobsStagesCount. Response for […]