我试图通过POST请求在Slack中发布消息。 但是我得到400 Bad Request,请求无法满足。
我的POST请求是:
uri = URI.parse("https://hooks.slack.com/services/XXXYXXXYX/YYYXXXYYY/21slaajsajslkk212ks")
http = Net::HTTP.new(uri.host, uri.port)
header = { "Content-Type": "application/json" }
params = { text: changelog_diff }
request = Net::HTTP::Post.new(uri.request_uri, header)
request.body = params.to_json
http.request(request)
答案 0 :(得分:2)
所以问题是我没有设置Net :: http来使用ssl。 只需添加以下行:
http.use_ssl = true
并要求' openssl'在开始。
所以:
require 'net/http'
require 'uri'
require 'openssl'
uri =
URI.parse('https://hooks.slack.com/services/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')
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
header = { 'Content-Type': 'application/json' }
params = { text: 'Some text to post' }
request = Net::HTTP::Post.new(uri.request_uri, header)
request.body = params.to_json
http.request(request)
希望能帮到你!