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);
}
}