import java.io.*;
import java.net.*;
import java.nio.charset.StandardCharsets;
public class Main {
public static void main(String[] args) throws Exception {
// doc_type: html | text
// - html: html_content 필수
// - text: text_content 필수
//
// is_private: 기본 0(공개)
// - 1이면 password 필수
String apiKey = "your_API_KEY";
URL u = new URL("https://nly.kr/api/pdf_save");
HttpURLConnection con = (HttpURLConnection) u.openConnection();
con.setRequestMethod("POST");
con.setConnectTimeout(5000);
con.setReadTimeout(30000);
con.setDoOutput(true);
con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
con.setRequestProperty("Accept", "application/json");
StringBuilder body = new StringBuilder();
body.append("api_key=").append(URLEncoder.encode(apiKey, "UTF-8"));
body.append("&doc_type=").append(URLEncoder.encode("html", "UTF-8"));
body.append("&doc_title=").append(URLEncoder.encode("API HTML 테스트", "UTF-8"));
body.append("&is_private=").append(URLEncoder.encode("0", "UTF-8"));
body.append("&password=").append(URLEncoder.encode("", "UTF-8"));
body.append("&html_content=").append(URLEncoder.encode("<h1>Hello</h1><p>API 저장 테스트</p>", "UTF-8"));
try (OutputStream os = con.getOutputStream()) {
os.write(body.toString().getBytes(StandardCharsets.UTF_8));
}
int code = con.getResponseCode();
InputStream is = (code >= 200 && code < 400) ? con.getInputStream() : con.getErrorStream();
StringBuilder sb = new StringBuilder();
try (BufferedReader br = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8))) {
String line;
while ((line = br.readLine()) != null) sb.append(line);
}
System.out.println("HTTP: " + code);
System.out.println(sb.toString());
}
}
import okhttp3.*
import java.util.concurrent.TimeUnit
fun main() {
// doc_type: html | text
// - html: html_content 필수
// - text: text_content 필수
//
// is_private: 기본 0(공개)
// - 1이면 password 필수
val apiKey = "your_API_KEY"
val client = OkHttpClient.Builder()
.connectTimeout(5, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
.build()
val body = FormBody.Builder()
.add("api_key", apiKey)
.add("doc_type", "html")
.add("doc_title", "API HTML 테스트")
.add("is_private", "0")
.add("password", "")
.add("html_content", "<h1>Hello</h1><p>API 저장 테스트</p>")
.build()
val request = Request.Builder()
.url("https://nly.kr/api/pdf_save")
.addHeader("Accept", "application/json")
.post(body)
.build()
client.newCall(request).execute().use { res ->
println("HTTP: \${res.code}")
println(res.body?.string())
}
}
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
class Program {
static async Task Main() {
// doc_type: html | text
// - html: html_content 필수
// - text: text_content 필수
//
// is_private: 기본 0(공개)
// - 1이면 password 필수
var apiKey = "your_API_KEY";
using var client = new HttpClient { Timeout = TimeSpan.FromSeconds(30) };
client.DefaultRequestHeaders.Add("Accept", "application/json");
var content = new FormUrlEncodedContent(new[] {
new KeyValuePair<string, string>("api_key", apiKey),
new KeyValuePair<string, string>("doc_type", "html"),
new KeyValuePair<string, string>("doc_title", "API HTML 테스트"),
new KeyValuePair<string, string>("is_private", "0"),
new KeyValuePair<string, string>("password", ""),
new KeyValuePair<string, string>("html_content", "<h1>Hello</h1><p>API 저장 테스트</p>"),
});
var res = await client.PostAsync("https://nly.kr/api/pdf_save", content);
var body = await res.Content.ReadAsStringAsync();
Console.WriteLine("HTTP: " + (int)res.StatusCode);
Console.WriteLine(body);
}
}
require "net/http"
require "uri"
# doc_type: html | text
# - html: html_content 필수
# - text: text_content 필수
#
# is_private: 기본 0(공개)
# - 1이면 password 필수
api_key = "your_API_KEY"
uri = URI("https://nly.kr/api/pdf_save")
req = Net::HTTP::Post.new(uri)
req["Accept"] = "application/json"
req.set_form_data({
"api_key" => api_key,
"doc_type" => "html",
"doc_title" => "API HTML 테스트",
"is_private" => "0",
"password" => "",
"html_content" => "<h1>Hello</h1><p>API 저장 테스트</p>",
})
res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true, open_timeout: 5, read_timeout: 30) do |http|
http.request(req)
end
puts "HTTP: #{res.code}"
puts res.body
use reqwest::Client;
use std::collections::HashMap;
use std::time::Duration;
#[tokio::main]
async fn main() {
// doc_type: html | text
// - html: html_content 필수
// - text: text_content 필수
//
// is_private: 기본 0(공개)
// - 1이면 password 필수
let api_key = "your_API_KEY";
let mut form = HashMap::new();
form.insert("api_key", api_key);
form.insert("doc_type", "html");
form.insert("doc_title", "API HTML 테스트");
form.insert("is_private", "0");
form.insert("password", "");
form.insert("html_content", "<h1>Hello</h1><p>API 저장 테스트</p>");
let client = Client::builder()
.timeout(Duration::from_secs(30))
.build()
.unwrap();
let res = client
.post("https://nly.kr/api/pdf_save")
.header("Accept", "application/json")
.form(&form)
.send()
.await
.unwrap();
let status = res.status();
let body = res.text().await.unwrap();
println!("HTTP: {}", status);
println!("{}", body);
}