How to set a Header field on POST a form?
It cannot be done - AFAIK.
However you may use for example jquery (although you can do it with plain javascript) to serialize the form and send (using AJAX) while adding your custom header.
Look at the jquery serialize
which changes an HTML FORM into form-url-encoded
values ready for POST.
My suggestion is to include either
- a hidden form element
- a query string parameter
How to submit a HTML form with header
I want to submit a form including a header during posting the request , is that possible ?
No.
You can only add custom HTTP headers to a request if you are using XMLHttpRequest or fetch to make the request (so you can't if you are using a form submission to make the request).
You could use the submit
event to intercept the form submission and make the request with XMLHttpRequest or fetch instead … but then you'd need to handle the response with JS too.
Add custom header on non-ajax post
Yes, the sentence implies that the POST operation is invoked by a custom JavaScript handler in order to inject the AUTH header. I've corrected the OWASP description to reflect this oversight.
How to set custom header on form-data item?
I found the solution myself, and its very simple.
Its posible to set custom headers in the options object header property
router.get('/getdata', async (req, res, next) => {
var form = new FormData();
var encodedImage2 = fs.readFileSync('./public/image2.png');
var options = {
header: {
'X-Custom-Header': 123
}
};
form.append('image2.png', encodedImage2, options);
res.set('Content-Type', 'multipart/form-data; boundary=' + form.getBoundary());
form.pipe(res);
});
Related Topics
Input Date Format With Dd/Mm/Yyyy in the Input Field
How to Download File in React Js
How to Restrict Past Dates in Html5 Input Type Date
How to Refresh Form Page After Post Request
React Button Onclick Redirect Page
How to Detect Browser Refresh Using Angular
How to Move Focus on Next Field When Enter Is Pressed
Stringified Json Has Unwanted Double Quotes
Javascript Function Not Defined Error (But It Is Defined)
How to Detect Browser Back Button Click Event Using Angular
How to Tell If a String Contains a Certain Character in JavaScript
How to Download Fetch Response in React as File
How to Make New Line or Break in Array
How to Convert Jquery Code to JavaScript
The Use of the Triple Exclamation Mark
How to Reload Datatables from Another Ajax Request With Onclick