에서 클라이언트 측의 "Content-Type"헤더 설정 Meteor (v1.0) HTTP.call
메서드를 사용하여 헤더에 application/json
콘텐트 유형 만 허용하는 Python 기반 서버와 통신하려고합니다. 하지만 Meteor에서 클라이언트 측에서 API URL을 호출 할 때 HTTP 헤더를 올바르게 설정할 수는 없습니다. 나는이 같은 유성의 서버 측에서 같은 URL을 호출하면, 그러나Meteor
if (Meteor.isClient) {
Template.testing.events({
'click button': function(event, tpl) {
event.preventDefault();
var method = 'GET';
var url = 'http://localhost:6543/test';
var options = {
headers: {'Content-Type': 'application/json'}
}
HTTP.call(method, url, options, function(error, result) {
if (error) {
console.log('ERRR');
console.log(error);
} else
console.log('RESULT');
console.log(result);
});
}
});
}
:이 같은 조각으로
는 파이썬 서버에서415 (Unsupported Media Type)
오류가
if (Meteor.isClient) {
Template.testing.events({
'click button': function(event, tpl) {
event.preventDefault();
var method = 'GET';
var url = 'http://localhost:6543/test';
var options = {
headers: {'Content-Type': 'application/json'}
}
Meteor.call('APICall', method, url, options, function (error, result) {
if (error) {
console.log('CLIENT ERRR');
console.log(error);
} else {
console.log('CLIENT RESULT');
console.log(result);
}
});
}
});
}
if (Meteor.isServer) {
Meteor.methods({
APICall: function (method, url, options) {
HTTP.call(method, url, options, function(error, result) {
if (error) {
console.log('SERVER ERRR');
console.log(error);
} else
console.log('SERVER RESULT');
console.log(result);
});
}
});
}
나는 서버로부터 적절한 응답을 얻는다.
파이썬 측에서 가능한 모든 요청에 대해 CORS 출처를 활성화했습니다 (예 : cors_origins=('*')
).
그래서 ... 클라이언트 측에서 헤더를 설정할 수 있습니까? 아니면 항상 서버 측에서이 서비스를 호출해야합니까?
답변 해 주셔서 감사합니다. 궁금해서 "책"에 대해 언급하셨습니까? 어느 쪽 이냐? – errata
아! [이디엄입니다] (http://idioms.thefreedictionary.com/in+my+book). 내가 실제로 책을 썼 더라면 좋겠지 만 :) –
아 롤, 나는 본다 : 결코 그 하나를 지금까지 듣지 않았다 hahahaha :) – errata