How to do a POST in Javascript [duplicate]

1

I need to do a java script to execute a direct POST in the browser console. Based on this, I wanted to do this:

Used sites:

link link link

Request URL:http://csgobounty.com/v1/tips/send?token=877e556c058a396c3f9d9eb12c7ab04b015e2fc521fa81320ae3fbf53c41428d4865378bd051e8d0752c90ff098e88a74f3a5666303cbc1b857ec93253352b855d9b5eaf87c8e54e768f8a90314eea557a79e1b5cb6832f1121aafc7459d065e
Request Method:POST
Status Code:400 Bad Request
Remote Address:104.24.6.12:80
Referrer Policy:no-referrer-when-downgrade
Response Headers
view source
Access-Control-Allow-Credentials:true
Access-Control-Allow-Methods:HEAD, GET, POST, PUT, PATCH, DELETE
Access-Control-Allow-Origin:*
Access-Control-Max-Age:60
Cache-Control:no-cache
CF-RAY:3b8298b6557c4b3f-GRU
Connection:keep-alive
Content-Length:21
Content-Type:application/json
Date:Fri, 03 Nov 2017 21:58:43 GMT
Server:cloudflare-nginx
Set-Cookie:token=877e556c058a396c3f9d9eb12c7ab04b015e2fc521fa81320ae3fbf53c41428d4865378bd051e8d0752c90ff098e88a74f3a5666303cbc1b857ec93253352b855d9b5eaf87c8e54e768f8a90314eea557a79e1b5cb6832f1121aafc7459d065e; expires=Sun, 03-Dec-2017 21:58:43 GMT; Max-Age=2592000; path=/
Vary:Origin
X-Frame-Options:SAMEORIGIN
Request Headers
view source
Accept:application/json, text/plain, */*
Accept-Encoding:gzip, deflate
Accept-Language:pt-BR,pt;q=0.8,en-US;q=0.6,en;q=0.4
Connection:keep-alive
Content-Length:29
Content-Type:application/json;charset=UTF-8
Cookie:__cfduid=db39b041e9acf72e863eb4ff2ed93e4131500559620; cf_clearance=6b2825f39a7fd4a986032b0970912dfffd991bf9-1509737595-86400; _ga=GA1.2.1979710359.1500559625; _gid=GA1.2.420014464.1509737594; token=877e556c058a396c3f9d9eb12c7ab04b015e2fc521fa81320ae3fbf53c41428d4865378bd051e8d0752c90ff098e88a74f3a5666303cbc1b857ec93253352b855d9b5eaf87c8e54e768f8a90314eea557a79e1b5cb6832f1121aafc7459d065e
Host:csgobounty.com
Origin:http://csgobounty.com
Referer:http://csgobounty.com/
User-Agent:Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36
Query String Parameters
view source
view URL encoded
token:877e556c058a396c3f9d9eb12c7ab04b015e2fc521fa81320ae3fbf53c41428d4865378bd051e8d0752c90ff098e88a74f3a5666303cbc1b857ec93253352b855d9b5eaf87c8e54e768f8a90314eea557a79e1b5cb6832f1121aafc7459d065e
Request Payload
view source
{amount: 1, user_id: 574648}
amount
:
1
user_id
:
574648

The project looks like this:

var tem=document.getElementsByClassName("amount")[0].innerHTML;var request=new XMLHttpRequest;request.open("POST","http://csgobounty.com/v1/tips/send?token="+localStorage.getItem("SESSION"),!0),request.setRequestHeader("Content-Type","application/json;charset=UTF-8"),request.send("user_id=1466934&amount="+tem);
    
asked by anonymous 03.11.2017 / 23:02

1 answer

1

Try a JQUERY, remembering that you have to have a POST-enabled route. Then it would look like this:

<script
  src="https://code.jquery.com/jquery-3.2.1.min.js"integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
  crossorigin="anonymous">
</script>

<script>
$.ajax({
  type: "POST",
  url: url_do_post,
  data: data,
  success: func(data){ 
    console.log('dados inseridos com sucesso');
  },
});
</script>

in url you can put something like this: link

Remembering that your PATH has been properly enabled to receive this type of request.

    
03.11.2017 / 23:27