I want to send data with a PUT request.
I have an input field for the data to send. with submit I want to send the data.
my data are in JSON format.
This is only for a pentest - so it has to be a PUT Request
Here is the code:
<header>
<meta charset="UTF-8">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script type="javascript">
$(document).ready(function(){
$(#submit).click(){
var xmlHttp = getNewHTTPObject(); //returns a XMLHttpRequest object
function chargeURLPut(url) {
var mimeType = "text/plain";
xmlHttp.open('PUT', url, true); // true : asynchrone false: synchrone
xmlHttp.setRequestHeader('Content-Type', mimeType);
xmlHttp.send($(#data).val();
}}});
</script>
</header>
<body>
<form>
Data:<br>
<input id="data" type="text" name="data" value="Mickey"><br>
<input id="submit" type="submit" value="Submit">
</form>
</body>
</html>
But the data are added to the URL like GET-Parameters. After the HTTP header, I want data like "{date: foo....}"
Here is an example Request below:
PUT /foo/bar/v1/users HTTP/1.1
Host: www.foo.bar
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0
Accept: */*
Accept-Language: de,en-US;q=0.7,en;q=0.3
Accept-Encoding: gzip, deflate, br
Referer: https://www.foo.bar/frontend/
Content-Type: application/json;charset=UTF-8
Authorization: eyJhbGciOiJSUzUxMiJ9.eyJzdW
origin: https://www.foo.bar
Content-Length: 598
Connection: close
{foo: bar, foo:bar}
Sending a PUT Request with Axios The simplest way to make the PUT call is to simply use the put() function of the axios instance, and supply the body of that request in the form of a JavaScript object: const res = await axios. put('/api/article/123', { title: 'Making PUT Requests with Axios', status: 'published' });
HTTP PUT request PUT updates the entire resource with data that is passed in the body payload. If there is no resource that matches the request, it will create a new resource. In our weather app, we could use PUT to update all weather data about a specific city.
Requests using GET should only be used to request data (they shouldn't include data). Note: Sending body/payload in a GET request may cause some existing implementations to reject the request — while not prohibited by the specification, the semantics are undefined.
You could try using the $.ajax call.
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#submit').click( function () {
console.log("click");
var sendData = $('#data').val();
$.ajax({
url: 'localhost', //Your api url
type: 'PUT', //type is any HTTP method
data: {
data: sendData
}, //Data as js object
success: function () {
}
})
;
});
});
</script>
</head>
<body>
<form>
Data:<br>
<input id="data" type="text" name="data" value="Mickey"><br>
<input id="submit" type="button" value="Submit">
</form>
</body>
</html>
I tested this on a webserver. It works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With