각도에서 데이터를 가져오고 모든 것이 정상적으로 작동합니다. 각도로부터 값을 얻고 내 로컬 dB에 저장할 수 있습니다. 하지만 실제로는 쇼 아래와 같이 웹 브라우저에서 백엔드 서버에 갈 때 단지각도가
이서버가 아무 문제없이 데이터를 수신 것 같다
를 얻을 수 없다, 실현 그런데 왜 그것을 않습니다 이 오류를 표시 하시겠습니까?
백엔드
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
var sql = require('mssql');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.all("/*", function (req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization, Content-Length, X-Requested-With');
next();
});
app.listen(1433, function() { console.log('Example app listening on port 1433!') })
var config = {
server: "",
database: "",
user: "",
password: "",
port: 1433
};
app.post('/ping', function (req, res) {
res.send(res.body);})
angular4
this.appService.http.post('http://localhost:1433/ping', getAll, { headers: Headers })
.subscribe(data => {
console.log(data), (err) => console.error("Failed! " + err);
})
'액세스 제어 - 허용 - 원산지 : *'당신의 웹 사이트에 소비하는 것을 의미하는 API에 매우 위험합니다. 프로덕션 환경에서하지 마십시오 - 원본 도메인 간 원본 공유에 대해 허용 된 액세스를 사용자가 인식하는 도메인으로 제한하십시오. –
또한'res.body'는'req.body'이어야합니다. 오타가 있습니다 –