api ¼¹ö¿¡ post ¿äûÇÏ´Â ³»¿ëÀ» html ·Î °£´ÜÇÏ°Ô ÀÛ¼ºÇߴµ¥¿ä..
2°¡Áö ¹æ¹ýÀ¸·Î ¿äûÇßÀ¸³ª
{"type":"https://tools.ietf.org/html/rfc7231#section-6.5.13","title":"Unsupported Media Type","status":415,"traceId":"00-41808cde0d4cf94c3c84e9d91e960223-076264ce7f4ffcdb-00"}
À§¿Í °°Àº ¿¡·¯ ¸Þ½ÃÁö°¡ ¶ß¸é¼ ¾ÈµË´Ï´Ù. Á¦°¡ ¾Ë±â·Ð 415 ¿¡·¯°¡ json Çü½ÄÀ¸·Î µ¥ÀÌÅ͸¦ ³Ñ±âÁö ¾Ê¾Æ¼ ±×·±°É·Î ¾Ë°í Àִµ¥¿ä.
html ·Î post ¿äûÀ» ÀÛ¼ºÇÒ ¶§ content typeÀ» json À¸·Î Çصµ ¾ÈµÇ³×¿ä,, (swagger ·Î json µ¥ÀÌÅÍ Æ÷ÇÔÇؼ post ¿äûÇϰųª, postman ÇÁ·Î±×·¥À» ÅëÇØ json µ¥ÀÌÅÍ Æ÷ÇÔÇؼ post ¿äûÇϸé Àß µË´Ï´Ù,..)
¾Æ·¡ html ÄÚµå´Â Á¦°¡ ÇØ º» °Í ÀÔ´Ï´Ù,, ¹«¾ùÀÌ ¹®Á¦ Àϱî¿ä?
==========================
ù¹ø° html
===================
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>JSON ÆÄÀÏ ¼±ÅÃÇϱâ</title>
</head>
<body>
<form method="post" action="http://192.168.0.69:8080/api/withdraw" enctype="application/json">
<input type="file" name="json_file" accept=".json">
<button type="submit">Àü¼Û</button>
</form>
</body>
</html>
====================
µÎ¹ø° html
=-===================
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>JSON ÆÄÀÏ ¼±ÅÃÇϱâ</title>
</head>
<body>
<form method="post" action="http://192.168.0.69:8080/api/withdraw" enctype="application/json">
<input type="file" name="json_file" accept=".json" onchange="loadFile(event)">
<button type="submit" onclick="sendJson()">Àü¼Û</button>
</form>
<script>
function loadFile(event) {
const input = event.target;
if ('files' in input && input.files.length > 0) {
readJSON(input.files[0]);
}
}
function readJSON(file) {
const reader = new FileReader();
reader.onload = function(event) {
const contents = event.target.result;
const jsonData = JSON.parse(contents);
document.getElementById("json_data").value = JSON.stringify(jsonData);
};
reader.readAsText(file);
}
function sendJson() {
const jsonData = document.getElementById("json_data").value;
const xhr = new XMLHttpRequest();
xhr.open("POST", "http://192.168.0.69:8080/api/withdraw");
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send(jsonData);
}
</script>
<textarea id="json_data" style="display:none;"></textarea>
</body>
</html>
|
Ȥ½Ã enctype¿¡¼ application/jsonÀÌ Áö¿øµÇ´Â Æ÷¸ËÀϱî¿ä? content-type:application/jsonÀº ¸¹ÀÌ »ç¿ëÇߴµ¥, enctypeÀº Àúµµ Àß ¸ô¶ó¼ ±Ã±ÝÇؼ ´ñ±Û µå¸³´Ï´Ù.!