Making a simple POST request with the pastebin API

北城余情 提交于 2021-02-10 15:57:59

问题


I was wondering how I would be able to make a post request to pastebin.com. They have an easy to understand API documentation, but whenever I run a simple POST request I always get Bad API request, invalid api_option.

I'm using the bear minimum required to make the request, I'm not sure what I could be doing wrong.

var request = new XMLHttpRequest; request.open("POST", "https://pastebin.com/api/api_post.php?api_dev_key=mykey&api_option=paste&api_paste_code=hi", false); request.send(); request.response;


回答1:


Finally I made it work like this:

var request = new XMLHttpRequest();

request.open("POST", "https://pastebin.com/api/api_post.php", true);

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

request.send("api_dev_key=YOUR_KEY_HERE&api_option=paste&api_paste_private=0&api_paste_name=myname.js&api_paste_expire_date=10M&api_paste_format=javascript&api_paste_code=random");

I hope it helps



来源:https://stackoverflow.com/questions/50430229/making-a-simple-post-request-with-the-pastebin-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!