-
-
Save gregglind/8749e3b0658e28d18554 to your computer and use it in GitHub Desktop.
CORS from firefox CLI for https://bugzilla.mozilla.org/show_bug.cgi?id=1126030
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
/** CORS test script | |
tools > web developer > web console. | |
Paste and run. | |
Results: | |
- if CORS off, will `console.log` about it. | |
- else will log 201, or 400. | |
*/ | |
var Cors = function(url, dataObject) { | |
var req = new XMLHttpRequest(); | |
req.open('post', url); | |
req.setRequestHeader("Content-Type", 'application/json'); // will trigger pre-flight | |
req.onload = function() { | |
console.log(req.status, req.statusText, req.getAllResponseHeaders()); | |
if (req.status >= 200 && req.status < 300) { | |
console.log(req.response); | |
} else { | |
console.error(Error(req.statusText)); | |
} | |
}; | |
req.onerror = function(e) { | |
console.log(e); | |
console.error(Error('Network Error')); | |
}; | |
req.send(JSON.stringify(dataObject || {})); | |
}; | |
var Data = function () { | |
return { | |
"person_id": "gregg", | |
"survey_id": "lunch", | |
"flow_id": "12345", | |
"experiment_version": "1", | |
"response_version": 1, | |
"question_id": "howwaslunch", | |
"question_text": "how was lunch?", | |
"variation_id": "1", | |
"updated_ts": Date.now(), | |
"is_test": true | |
} | |
} | |
//Cors("http://127.0.0.1:5000/"+Date.now()); | |
Cors("https://input.mozilla.org/api/v2/hb/", Data()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment