dva/fetch ์์ฒญ์ ์ฌ์ฉํ ๋ ์ฟ ํค๊ฐ ์ ๋ฌ๋์ง ์์ผ๋ฏ๋ก ๊ฐ ์์ฒญ์ ๋ํด ๋ค๋ฅธ ์ธ์ ์ด ๋ฐ์ํฉ๋๋ค.
๋ธ๋ผ์ฐ์ ๊ธฐ๋ณธ ์์ฒญ์ ์ฟ ํค๋ฅผ ๊ฐ์ ธ์ต๋๋ค.
GET http://localhost/jinxin/php/api/user/registerSeller HTTP/1.1
Host: localhost
Connection: keep-alive
Cache-Control: max-age=0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36
Accept-Encoding: gzip, deflate, sdch
Accept-Language: zh-CN,zh;q=0.8,en;q=0.6
Cookie: PHPSESSID=2i3s2tp2p2oddsc8u1643epus3
FETC ์์ฒญ์ ์ฌ์ฉํ ๋ ์ฟ ํค๋ฅผ ์ด๋ฐํ์ง ์๊ธฐ ๋๋ฌธ์ ๋งค๋ฒ ์๋ฒ์ ์ธ์
์ด ๋ฌ๋ผ์ง๋ฉฐ ๋ก๊ทธ์ธ ์ํ๋ฅผ ํ๋จํ ์ ์์ต๋๋ค.
GET http://localhost/jinxin/php/api/user/registerSeller HTTP/1.1
Host: localhost
Connection: keep-alive
Origin: http://localhost:8989
User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1
Accept: */*
Referer: http://localhost:8989/
Accept-Encoding: gzip, deflate, sdch
Accept-Language: zh-CN,zh;q=0.8,en;q=0.6
๋ค์์ ์ฐธ์กฐํ์ญ์์ค.
@yunfeit ๊ฐ๋จํ ์๋๋ฆฌ์ค, https://github.com/hbrls/vanilla.js ์๋๋ฅผ ํ์ํฉ๋๋ค.
๊ฐ์ ธ์ค๊ธฐ ์ต์
์ ์ค์ ํ๋ฉด ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
const options= { method: "GET",mode: 'cors',credentials: 'include'};//same-origin
cors๋ฅผ ์ฌ์ฉํ๊ธฐ ๋๋ฌธ์ ์๊ฒฉ ์ฆ๋ช
์ด ํฌํจ๋๋๋ก ์ค์ ๋์ด ์์ผ๋ฉฐ ํฌ๋ก์ค ๋๋ฉ์ธ์ด ์๋๋ฉด ๋์ผ ์ถ์ฒ๊ฐ ๋ฉ๋๋ค.
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
๊ฐ์ ธ์ค๊ธฐ ์ต์ ์ ์ค์ ํ๋ฉด ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
const options= { method: "GET",mode: 'cors',credentials: 'include'};//same-origin
cors๋ฅผ ์ฌ์ฉํ๊ธฐ ๋๋ฌธ์ ์๊ฒฉ ์ฆ๋ช ์ด ํฌํจ๋๋๋ก ์ค์ ๋์ด ์์ผ๋ฉฐ ํฌ๋ก์ค ๋๋ฉ์ธ์ด ์๋๋ฉด ๋์ผ ์ถ์ฒ๊ฐ ๋ฉ๋๋ค.