I am not able to do a post request using XMLHttpRequest (The code will be run in client's side). Here's my code: (Basically I want to check the output of any python code by sending a post request to an online service that does this job for me)
var code = "print('hey')"
var input = "";
var data = new FormData();
var params = {'LanguageChoiceWrapper': "24",
'EditorChoiceWrapper':'1',
'LayoutChoiceWrapper':'1',
'Program': code,
'Input': input,
'Privacy': '',
'PrivacyUsers': '',
'Title': '',
'SavedOutput':'',
'WholeError':'',
'WholeWarning': '',
'StatsToSave': '',
'CodeGuid': '',
'IsInEditMode': 'False',
'IsLive': 'False'
}
for (name in params) {
data.append(name, params[name]);
}
var xhr = new XMLHttpRequest();
xhr.open('POST', 'https://rextester.com/rundotnet/Run', true);
xhr.onload = function () {
// do something to response
console.log(this.responseText);
};
xhr.send(data);
When running it, this error happens
When sending the same information through postman it works just fine and returns everything I want ... I ran into multiple threads but I was not able to make it work just by replacing the 'url' and 'params' fields in the answers of them. Here are two threads I ran through: 1 2