0

I want to execute a POST request with a user-agent of my choice . I read that user-agent is not in the forbidden list as per mozilla documentation : https://developer.mozilla.org/en-US/docs/Glossary/Forbidden_header_name . I want to post some data with a user-agent . I tried below code

<!DOCTYPE html>
<html>
<head>

<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">
<script>
"use strict";
function submitForm()
{
  var xhr = new XMLHttpRequest();
  var url = 'example.com';
  xhr.open ('POST', url, true);
  xhr.setRequestHeader('User-Agent', ' myagent');

  xhr.withCredentials = 'true';
  xhr.send ('data');
  return false;
}
</script>
</head>

<body>
<form method="post" name="myform"  onsubmit="return submitForm();">
  <input type="submit" value="Submit request" />
</form>
</body>
</html></html>

I want to override the default user-agent for the post request to the url. What I need is a working HTML code to post data to form with a user-agent set using XHR

NB: I am not good with js , please provide a working code rather than documentation

Joel Deleep
  • 1,308
  • 2
  • 14
  • 36

0 Answers0