Last active
May 7, 2017 21:18
-
-
Save SteveLTN/c331b9c864598f81878b4296adc9ad4a to your computer and use it in GitHub Desktop.
For blog post
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
const url = 'http://site.alice.com/posts' | |
fetch(url, { method: "GET", credentials: 'include' }). | |
then((response) => response.text()). | |
then((body) => { | |
const re = new RegExp('<meta name="csrf-token" content="(.*)" />') | |
const csrfToken = re.exec(body)[1] | |
return csrfToken | |
}). | |
then((csrfToken) => { | |
const headers = new Headers({'X-CSRF-Token': csrfToken}) | |
fetch(url, { | |
method: 'POST', | |
headers: headers, | |
credentials: 'include' | |
}) | |
}) | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment