게시물 요청을 보내는 index.html이 localhost:3000/SetUser
있지만 항상 오류가 발생합니다.XMLHttpRequest cannot load https://localhost:3000/SetUser. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://localhost' is therefore not allowed access.
이것은 내 Angular 컨트롤러의 코드입니다.
$http.post("https://localhost:3000/SetUser", {'a':'b'}).success(function(data, status, headers, config) {
console.log('data', data);
});
그리고 이것은 내 server.js (nodejs)의 코드입니다. app.post
app.post('/SetUser', function(req, res) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "X-Requested-With");
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
res.end();
console.log("New user added ", req.body);
});
나는 이것을 고치기 위해 무엇을 할 수 있는지 더 이상 확신하지 못했지만 모든 것을 시도했습니다. 감사!
모든 것이 동일한 포트에서 실행되는지 확인하고 문제를 해결해야하며, 그의 오류를 통해 그가 포트 80에서 포트 3000으로 요청을 보내는 것은 이해할 수 있습니다. 동일한 포트에서 앱을 해결하지 못하게하는 이유는 무엇입니까?
자신을 더 잘 설명해야합니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다