【发布时间】:2018-01-26 14:16:49
【问题描述】:
当我在节点服务器上打印请求内容时,我无法在任何地方看到用户数据。
这是我的节点服务器:
var http = require('http');
http.createServer( function (request, response) {
console.log(request);
}).listen(8080);
console.log('Server running at http://127.0.0.1:8080/');
这里是 Angular2 代码:
import { Component, OnInit } from '@angular/core';
import { HttpClient } from "@angular/common/http";
import { Http, Response, Headers , RequestOptions } from "@angular/http";
import 'rxjs/add/operator/retry'; // to be able to retry when error occurs
import { Observable } from "rxjs/Rx";
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit{
title = 'Angular Test';
user = { id : 1, name : "Hello"};
constructor (private http: Http) {}
ngOnInit(): void {
let headers = new Headers({ 'Content-Type': 'application/json' });
let options = new RequestOptions({ headers: headers });
console.log(this.user);
this.http.post("http://localhost:8080/", this.user, options)
.subscribe(
(err) => {
if(err) console.log(err);
console.log("Success");
});
}
}
任何人都可以帮助我或解释如何以角度处理 http 请求。
【问题讨论】:
-
你在 Node.JS 中使用 express 框架吗?
-
你在 nodejs 中使用 expressjs 吗?
-
@Darshita 我没有在 Node 中使用 express.js。好点了吗?
-
@echonax。不,我不是。是不是更好。