[英]Send data with PUT-Request
I want to send data with a PUT request.我想用 PUT 请求发送数据。
I have an input field for the data to send.我有一个用于发送数据的输入字段。 with submit I want to send the data.
随着提交我想发送数据。
my data are in JSON format.我的数据是 JSON 格式。
This is only for a pentest - so it has to be a PUT Request这仅用于渗透测试 - 所以它必须是一个 PUT 请求
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.但是数据会像 GET-Parameters 一样添加到 URL 中。 After the HTTP header, I want data like "{date: foo....}"
在 HTTP 标头之后,我想要像“{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}
You need to send the data as x-www-form-urlencoded
您需要将数据发送为
x-www-form-urlencoded
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
And you have to call the defined function inside the .click() 你必须在.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. 您可以尝试使用$ .ajax调用。
<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.
有用。
在无脂肪我使用这个
$data = json_decode($f3->get('BODY') , true);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.