@sorrycc utils / request.js์์ ํค๋๋ฅผ ์ค์ ํ๊ณ ๋ธ๋ผ์ฐ์ ์์ http ์์ฒญ์ ํ์ธํ ๋ค์ ์์ฒญ ํค๋์ ์ ์ฉ๋์ง ์๋์ง ํ์ธํฉ๋๋ค.
request.js ์ฝ๋ :
fetch(url, {
body:"name=%E4%B8%AD%E6%96%87&mobile=121212121&password=111111&captcha=sdsds",
method:"post",
mode:"no-cors",
headers:{
Accept:"application/json",
Authorization:"Bearer dfdfdfdfdfdfdf",
Content-Type:"application/json"}
});
๋ธ๋ผ์ฐ์ ์ ํ์๋ ์์ฒญ ํค๋๋ ์ ์ฉ๋์ง ์์ต๋๋ค.
์๋ฝ : application / json
content- type : text / plain; charset = UTF-8
ํค๋ ์ ๋ณด๋ฅผ ์ค์ ํ๋ ๋ฐฉ๋ฒ์ ์๋ ค์ฃผ์ธ์. ์๋ฅผ ๋ค์ด, ํ ํฐ์ ํค๋์ ์ฑ์ฐ์๊ฒ ์ต๋๊น?
https://www.npmjs.com/package/whatwg-fetch#post -json์ ์ฐธ์กฐํ์ญ์์ค.ํ์ง๋ง ์ฝ๋๊ฐ ์ข์ ๋ณด์ด๊ณ ๊ด์ฐฎ์ต๋๋ค.
์ข์ต๋๋ค. ๋ค์ ์๋ํ๊ฒ ์ต๋๋ค.
Content-Type์ ๋ฐ์ดํ๋ก ๋ฌถ์ด์ผํฉ๋๋ค.
@xaviertung ๋ฌธ์ ๋ฅผ ํด๊ฒฐ ํ์ต๋๊น, ํด๊ฒฐ ๋ฐฉ๋ฒ์ ๋ฌผ์ด๋ณด์ญ์์ค. ์ค๋ซ๋์
์๋ ํ์ธ์, @huzhengke , @lincenying ์ ๊ธ์ ์ ์ธ ํด๊ฒฐ์ฑ ์ด์ด์ผํฉ๋๋ค
@monkindey ๋ ๊ณต์ ์น ์ฌ์ดํธ์ ๋ฐ๋ฅด๋ฉด ์ฌ์ ํ ์ธ๋ชจ๊ฐ ์๋ค๊ณ ์ธ์ฉ ๋ถํธ๋ฅผ ์ถ๊ฐํฉ๋๋ค.
@huzhengke ํด๊ฒฐ ๋์์ต๋๊น? ์๋ก ์จ ์ฌ๋์ด ๋ค์ ๊ตฌ๋ฉ์ด์ ์์ต๋๋ค. . . .
์ด๋ฌ ์ผ ํด
fetch(
new Request(`${API}${path}`, {
headers: new Headers({ Authorization: `Bearer ${TOKEN}`, 'Content-Type': 'application/json' }),
}),
)
.then(res => res.json());
ํต์ฌ์ ์์ฒญ ๋ฐ ํค๋ ๊ฐ์ฒด๋ฅผ ์ฌ์ฉํ๋ ๊ฒ์ ๋๋ค.
@xaviertung ๋น์ ์ ๋ชจ๋๋ฅผ 'cors'๋ก ์ค์ ํ๊ณ 'no-cors'๋ฅผ ์ฌ์ฉํ์ง ๋ง์ญ์์ค.
ํด๊ฒฐ์ฑ ์ด ์์ต๋๊น?
@suedar, ๋๋ฅผ ๋ณผ ์ ์์ต๋๊น
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
@xaviertung ๋น์ ์ ๋ชจ๋๋ฅผ 'cors'๋ก ์ค์ ํ๊ณ 'no-cors'๋ฅผ ์ฌ์ฉํ์ง ๋ง์ญ์์ค.