我正在尝试将Angular的http.post.request发送到mailgun。我收到的错误如下:
从原点“ https://api.mailgun.net/v3/sandbox7d2575b0a42a48d5b08508daff77e105.mailgun”到“ http://localhost:3000> .org / messages'的XMLHttpRequest的访问已被CORS策略阻止:Access不允许请求标头字段access-control-allow-origin -Control-Allow-Headers在飞行前响应中。
我知道这个问题已经问过了,但回答不正确。至少我不明白答案。 See here
public sendFeedback(form: NgForm) {
Object.assign(form.value, this.customer);
if(form.value) {
let headers = new Headers(
{
"Content-Type": "application/application-json",
"Authorization": "Basic " + this.apiKey,
"Access-Control-Allow-Origin": "http://localhost:3000",
"Access-Control-Allow-Credentials": "true",
"Access-Control-Allow-Methods": "GET,HEAD,OPTIONS,POST,PUT",
"Access-Control-Allow-Headers": "access-control-allow- credentials,access-control-allow-headers,access-control-allow-methods,access-control-allow-origin,authorization,content-type,*,http://localhost:3000",
}
);
let options = new RequestOptions({ headers: headers });
let body = "from=test@example.com&to=" + this.recipient + "&subject=" + this.subject + "&text=" + JSON.stringify(form.value);
this.http.post("https://api.mailgun.net/v3/" + this.mailgunUrl + "/messages", body, options)
.map(result => result.json())
.do(result => console.log("RESULT: ", JSON.stringify(result)))
.subscribe(result => {
console.log("SENT!" + result);
}, error => {
console.log(error);
});
}
}
我在这里做错了什么。感谢您的努力。我会很感激一个例子。