Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send data with PUT-Request

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}
like image 368
spitzbuaamy Avatar asked Jan 16 '17 16:01

spitzbuaamy


People also ask

How do you send a PUT request?

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' });

How does a PUT request work?

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.

Can you send data in the body of a GET request?

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.


1 Answers

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.

like image 109
kevingreen Avatar answered Sep 28 '22 17:09

kevingreen