๋ฌธ์
let url = `${TSP_SVR_URL}/fix_points`;
fetch(url, {
method: "POST",
headers: {
"Content-type": "applicaion/json",
},
body: JSON.stringify({
SPoint: pointList[0],
EPoint: pointList[0],
SPointList:{
nodes:pointList.slice(1, cnt)
},
}),
})
.then(response => response.json())
.then(body => {
console.log(body)
});
fetch ์์ฒญ ์์ response์ body๊ฐ ๋๋ฌด ๋ฆ๊ฒ ์ค๋ ํ์์ด์๋ค.
ํ๋ฆฌํ๋ผ์ดํธ๊ฐ ์ ์ผ ๋จผ์ ์ค๊ณ , ๊ทธ๋ค์ fetch response๊ฐ ๋ค์ด์ค๋๋ฐ ์๊ฐ์ด ๋ฌด๋ ค 5.14์ด์ด๋ค.
๋จ์ string๋ง ๋ฐ๋๋ฐ๋ ๋ง์ด๋ค.
preflight๊ฐ ๋ญ์งํด์ ์ฐพ์๋ณด๋ค๊ฐ ์๋ ๋ธ๋ก๊ทธ๋ฅผ ๋ณด๊ฒ ๋์๋๋ฐ "๊ฐ๋จํ ์์ฒญ"์ ๋ณด๋ด๊ธฐ ์ํ ์กฐ๊ฑด๋ค์ด ์ค๋ช ๋์ด์๋ค.
CORS ์๋ฏธ / ํ์ ์์ ์ง์ ๊ฒช์ CORS ์ด์์ ํด๊ฒฐ๋ฐฉ๋ฒ ์ ๋ฆฌ (tistory.com)
๊ทธ๋์ fetch์์ content-type์ text/plain์ผ๋ก ๋ณ๊ฒฝํ ํ์๋ ์๋ต์๋๊ฐ ์ ์์ผ๋ก ๋์์ค๊ณ preflight ์์ฒญ์ ๋์ด์ ๋๊ฐ์ง ์๋ ๊ฒ์ ํ์ธํ ์ ์์๋ค.
let url = `${TSP_SVR_URL}/fix_points`;
fetch(url, {
method: "POST",
headers: {
"Content-type": "text/plain"
},
body: JSON.stringify({
SPoint: pointList[0],
EPoint: pointList[0],
SPointList:{
nodes:pointList.slice(1, cnt)
},
}),
})
.then(response => response.json())
.then(body => {
console.log(body)
});
๋๊ธ