File name
Commit message
Commit date
File name
Commit message
Commit date
2025-05-08
File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
package itn.let.utl.user.service;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import org.springframework.stereotype.Service;
@Service("indexNowUtil")
public class IndexNowUtil {
private static final String INDEXNOW_API_URL = "https://api.indexnow.org/indexnow";
private static final String INDEXNOW_KEY = "d09a9f949e6e48eeb221d7a13bdb1d14"; // 🔁 여기에 실제 키 입력
private static final String HOST = "www.munjaon.co.kr"; // 🔁 도메인만 입력 (https:// 없이)
public static void submitUrl(String urlToSubmit) {
try {
URL url = new URL(INDEXNOW_API_URL);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/json; utf-8");
connection.setDoOutput(true);
// JSON 데이터 구성
String jsonInputString = "{"
+ "\"host\":\"" + HOST + "\","
+ "\"key\":\"" + INDEXNOW_KEY + "\","
+ "\"urlList\":[\"" + urlToSubmit + "\"]"
+ "}";
try (OutputStream os = connection.getOutputStream()) {
byte[] input = jsonInputString.getBytes(StandardCharsets.UTF_8);
os.write(input, 0, input.length);
}
int responseCode = connection.getResponseCode();
if (responseCode == 200 || responseCode == 202) {
System.out.println("✅ IndexNow 전송 성공: " + urlToSubmit);
} else {
System.out.println("❌ 전송 실패 - 응답 코드: " + responseCode + " : " + urlToSubmit);
}
} catch (Exception e) {
System.err.println("🚫 오류 발생: " + e.getMessage());
}
}
/*
public static void main(String[] args) {
// 테스트용 URL 전송
submitUrl("https://yourdomain.com/new-post.html"); // 🔁 여기에 전송할 실제 URL 입력
}
*/
}