团队,我需要帮助张贴一个简单的Json请求到Slack。我设置了配置并使用了URL。他们想让我加入payload={"Text":"Some String"}
我使用以下代码:
HttpPost httppost = new HttpPost("slackURL");
httppost.addHeader("Content-type", "application/json");
StringEntity params = new StringEntity("payload={\"text\" : \""+message+"\"}","UTF-8");
params.setContentType("application/json");
httppost.setEntity(params);错误信息:
HTTP/1.1 500 Server Error
Response content length: -1
Chunked?: true斯拉克的答复:
Our logs indicate that the content isn't being posted to the payload HTTP POST/form parameter.发布于 2016-05-25 15:40:19
变化
StringEntity params = new StringEntity("payload={\"text\" : \""+message+"\"}","UTF-8");至
StringEntity params = new StringEntity("{\"text\" : \""+message+"\"}","UTF-8");(去掉"payload=",因为这不是有效的JSON。)
对于每个文献资料,当POSTing到传入的web钩子URL时,您有两个选择:
payload表单编码参数。你在中间做了些什么..。您声称正在发送一个JSON编码的正文(通过Content-Type: application/json),但是没有发送有效的JSON。(您发送的东西看起来更像表单编码选项,但实际上并不是表单编码选项。)
顺便提一句:我强烈建议您使用真正的库来构建JSON。用手做是容易出错的。例如,如果您试图对消息A wise man once said "You shouldn't try to encode JSON by hand."进行编码,您将得到一个错误,因为您生成的JSON无效。
https://stackoverflow.com/questions/37423129
复制相似问题