我一直在互联网上寻找这个问题,但没有找到有效的答案。我正在尝试制作一个bukkit插件,该插件在运行命令时将数据发送到传入的Slack webhook。我已经注意到命令正在运行,但是我不知道如何发送JSON。(对于那些不熟悉Slack的人,终端窗口中的命令是curl -X POST --data-urlencode 'payload={"channel":"#slack-channel-id","username":"bot's username","text":"Self explanatory","icon_emoji":"The bot's icon"}' https://slack.com/custom/webhook/token/here
我一直在寻找并且在谷歌上搜索了好一小时,试图找到一种Java方式来发送此消息。但是不管我尝试什么,它都不会工作,感谢您的任何帮助,谢谢
//您可以使用以下代码起作用!slackWebhook是您可以从custom_integration链接获取的频道的https端点
String payload = "payload={\"channel\": \"#channel_name\", \"text\": \"This is posted " + "to #ewe_gps_abacus_notif and comes from a bot named change-alert.\"}"; StringEntity entity = new StringEntity(payload, ContentType.APPLICATION_FORM_URLENCODED); HttpClient httpClient = HttpClientBuilder.create().build(); HttpPost request = new HttpPost(slackWebhook); request.setEntity(entity); HttpResponse response = null; try { response = httpClient.execute(request); } catch (IOException e) { e.printStackTrace(); } System.out.println(response.getStatusLine().getStatusCode());