Dva: ์ž˜๋ชป๋œ ์„ธํŠธ ํ—ค๋” ๊ฐ€์ ธ ์˜ค๊ธฐ

์— ๋งŒ๋“  2016๋…„ 11์›” 15์ผ  ยท  11์ฝ”๋ฉ˜ํŠธ  ยท  ์ถœ์ฒ˜: dvajs/dva

@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

ํ—ค๋” ์ •๋ณด๋ฅผ ์„ค์ •ํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์•Œ๋ ค์ฃผ์„ธ์š”. ์˜ˆ๋ฅผ ๋“ค์–ด, ํ† ํฐ์„ ํ—ค๋”์— ์ฑ„์šฐ์‹œ๊ฒ ์Šต๋‹ˆ๊นŒ?

question

๊ฐ€์žฅ ์œ ์šฉํ•œ ๋Œ“๊ธ€

@xaviertung ๋‹น์‹ ์€ ๋ชจ๋“œ๋ฅผ 'cors'๋กœ ์„ค์ •ํ•˜๊ณ  'no-cors'๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ๋งˆ์‹ญ์‹œ์˜ค.

๋ชจ๋“  11 ๋Œ“๊ธ€

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, ๋‚˜๋ฅผ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๊นŒ

์ด ํŽ˜์ด์ง€๊ฐ€ ๋„์›€์ด ๋˜์—ˆ๋‚˜์š”?
0 / 5 - 0 ๋“ฑ๊ธ‰