slack test

Huiji Kim·2024년 5월 6일
0

module-info.java

module com.example.java_test {
    requires javafx.controls;
    requires javafx.fxml;
    requires java.net.http;


    opens com.example.java_test to javafx.fxml;
    exports com.example.java_test;
}
package com.example.java_test;

import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpRequest.BodyPublishers;

public class test {

    public static void main(String[] args) {

        // Slack Webhook URL
        String webhookUrl = ""; // SLACK_WEBHOOK_URL 환경 변수 가져오기
        // 보낼 메시지
        String json = "{\"text\": \"test123\"}";

        HttpClient client = HttpClient.newHttpClient();
        HttpRequest request = HttpRequest.newBuilder()
                .uri(URI.create(webhookUrl))
                .header("Content-Type", "application/json")
                .POST(BodyPublishers.ofString(json))
                .build();

        try {
            HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
            System.out.println("Response status code: " + response.statusCode());
            System.out.println("Response body: " + response.body());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
profile
새로 학습하는 내용을 기록합니다. \n 예전 주소 : https://blog.naver.com/gmlwl0720

0개의 댓글