我've been looking at this for a while now. I' m尝试使用chat.postMessage(https://slack.com/api/chat.postMessage)的网址向松弛 Channels 发布消息和一些按钮 . 这是存储在messagePostURL变量中的url . 我的PostingConstants.relevancePost变量保存了在https://api.slack.com/docs/message-buttons找到的交互式消息的松弛按钮教程上显示的确切JSON,并且我已将我的 Channels 名称和令牌添加到JSON代码中 . 发送到webhook时,相同的JSON代码可以正常工作,但不能直接将其发送到chat.postMessage网址 . 为什么这不能正常工作?
String urlParameters = PostingConstants.relevancePost;
byte[] postData = urlParameters.getBytes( StandardCharsets.UTF_8 );
int postDataLength = postData.length;
//String request = messagePostURL;
URL url = new URL( messagePostURL );
HttpURLConnection conn= (HttpURLConnection) url.openConnection();
conn.setDoOutput( true );
conn.setInstanceFollowRedirects( false );
conn.setRequestMethod( "POST" );
conn.setRequestProperty( "Content-Type", "application/x-www-form-urlencoded");
conn.setRequestProperty( "charset", "utf-8");
conn.setRequestProperty( "Content-Length", Integer.toString( postDataLength ));
conn.setUseCaches( false );
try( DataOutputStream wr = new DataOutputStream( conn.getOutputStream())) {
wr.write( postData );
}
打印conn.getResponseCode()给出200(这对我来说很好),打印conn.getResponseMessage()给出OK(再次应该是好的) .