How to make a POST in Javascript

Asked

Viewed 12,653 times

1

I need to make a java script to run a POST directly on the browser console. Based on this, I wanted to run this:

Sites used:

http://csgobounty.com https://gyazo.com/9f712dcc5e1e10f238f51f0fd7827d1f https://gyazo.com/cb1446ae6460941be889d6ac77cd2915

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 is 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);
  • @Leonardopessoa Sorry, there were two simultaneous editions. Could redo its editions?

  • @Victorstafusa made :)

  • Thanks I’m new I don’t know how to edit the questions

  • Below the javascript and post tags, you have the options - share, edit, flag.

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: http://localhost:4000/api/insert

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.