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=".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: /frontend/
Content-Type: application/json;charset=UTF-8
Authorization: eyJhbGciOiJSUzUxMiJ9.eyJzdW
origin:
Content-Length: 598
Connection: close
{foo: bar, foo:bar}
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}
Share
Improve this question
edited Sep 21, 2019 at 16:05
James-Jesse Drinkard
15.7k16 gold badges118 silver badges140 bronze badges
asked Jan 16, 2017 at 16:29
spitzbuaamyspitzbuaamy
7712 gold badges11 silver badges26 bronze badges
4
|
2 Answers
Reset to default 5You need to send the data as x-www-form-urlencoded
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
And you have to call the defined function inside the .click()
$(#submit).click(){
var xmlHttp = getNewHTTPObject(); //returns a XMLHttpRequest object
chargeURLPut('url');
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());
}
});
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.
type="javascript"
. – Ultimater Commented Jan 16, 2017 at 16:42xmlHttp.send($(#data).val();
should bexmlHttp.send($(#data).val());
– kevingreen Commented Jan 16, 2017 at 17:00