简体   繁体   中英

How to add settings on a post request using JavaScript

I am currently codding a website which will create a paste.ee document.

I fond some answers to the question "How to send a post request"

but I can't figure out a way to use the API settings in the API.

The API documentation: https://pastee.github.io/docs/

My code so far:

<html>
<body>
<script>
var request = new XMLHttpRequest();

request.open("POST", "https://api.paste.ee/v1/pastes", true);

request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

request.send("X-Auth-Token: mytoken");
</script>
</body>
</html>

If it's possible I would like to stay with JavaScript so I don't have to run PHP or python.

Just read carefully the API Docs. You need to specify the authentication token in the header like so:

var request = new XMLHttpRequest();

request.open("POST", "https://api.paste.ee/v1/pastes", true);

request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
request.setRequestHeader("X-Auth-Token", "YOUR_TOKEN_GOES_HERE");
request.send('{"description":"test","sections":[{"name":"Section1","syntax":"autodetect","contents":"Testing!"}]}')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM