Meteor HTTP包 - 不允许使用请求标头字段

时间:2016-02-24 16:52:18

标签: meteor http-headers

url = 'http://api.atompark.com/members/sms/xml.php'
xml = 'some xml'

当我使用jquery时,所有人都很尊敬:

$.ajax({
  method: 'POST',
  url: url,
  data: xml
}).done(function(r) {
  return log(r);
});

但是当我使用HTTP包时,我收到一个错误:

HTTP.post(url, {
  data: xml
}, function(e, r) {
  return log(r.content);
});

XMLHttpRequest cannot load http://api.atompark.com/members/sms/xml.php. Request header field Content-Type is not allowed by Access-Control-Allow-Headers in preflight response.

可能出现什么问题?

2 个答案:

答案 0 :(得分:1)

事实证明,我需要使用content代替data

HTTP.post(url, {
  content: xml
}, function(e, r) {
  return log(r.content);
});

https://forums.meteor.com/t/solved-http-package-request-header-field-is-not-allowed/18460

答案 1 :(得分:0)

默认的ContentType是x-www-form-urlencoded。

尝试在通话中指定内容类型。尝试下面的代码:

HTTP.post(url, {
    data: xml,
    headers: { "Content-Type": "application/xml"}
}, callback);