Skip to content

Instantly share code, notes, and snippets.

@shuuuuun
Last active September 7, 2022 13:37
Show Gist options
  • Save shuuuuun/9760aa4374d1b1ae8ee831f4e1755417 to your computer and use it in GitHub Desktop.
Save shuuuuun/9760aa4374d1b1ae8ee831f4e1755417 to your computer and use it in GitHub Desktop.
corsとか確認する用
// GET
fetch('https://example.com/api/count.json', {method: 'GET', mode: 'cors'}).then(d => d.json()).then(console.log).catch(console.error)
// POST
const headers = new Headers()
headers.append('Content-Type', 'application/json')
const body = JSON.stringify({ hoge: 'fuga' })
fetch('https://example.com/api/count.json', {method: 'POST', mode: 'cors', credentials: 'include', body, headers}).then(d => d.json()).then(console.log).catch(console.error)
@shuuuuun
Copy link
Author

$ http https://example.com/api/count.json Origin:'https://hogehoge.com'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment