无法从应用POST懈怠传入网络挂接
问题描述:
我能张贴到我的时差传入网络挂接使用curl:无法从应用POST懈怠传入网络挂接
curl -X POST -H 'Content-type: application/json' --data '{"text":"Hello world"}' https://hooks.slack.com/services/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
但是,当我在一个页面中使用
$.ajax({
url: "https://hooks.slack.com/services/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",
data: '{"text": "Hello world"}',
type: "POST",
contentType: "application/json"
})
.done(function (reply) {
console.log("POST to Slack succeeded")
})
.fail(function (xhr, status, errorThrown) {
console.log("Error in POST to Slack: " + errorThrown.toString())
})
我由本地主机提供服务的应用程序:8090,我得到的错误:
jquery.js:9536 OPTIONS https://hooks.slack.com/services/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
400 (Bad Request)
XMLHttpRequest cannot load https://hooks.slack.com/services/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.
Response for preflight has invalid HTTP status code 400
通常从我的页面中的POST会去到我的服务器,其服务的页面。所以我认为我的困惑与理解Webhooks的工作方式有关。我认为同源策略禁止我发布到任意网址。但是为什么curl命令能够工作,以及如何让我的页面执行curl的功能?
我需要从我的服务器而不是从客户端浏览器发送POST吗?
答
我从Slack的Ben J得到了答案。 我所要做的就是从松弛队删除行
contentType: "application/json"
精彩,快速帮助。不胜感激。