我现在已经看了一会儿。我试图使用chat.postMessage(https://slack.com/api/chat.postMessage)的网址向松弛频道发布消息和一些按钮。这是存储在messagePostURL变量中的url。我的PostingConstants.relevancePost变量保存了在https://api.slack.com/docs/message-buttons找到的交互式消息的松弛按钮教程上显示的确切JSON,并且我已将我的频道名称和令牌添加到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(再次应该是好的)。