我正在使用GM_xmlhttpRequest做一个简单的帖子,将一些文本发布到pastebin。这是我的代码
GM_xmlhttpRequest({
method: "POST",
url: "http://pastebin.com/post.php",
data: "api_dev_key=5c3***********************073a&api_option=paste&api_paste_code="+encodeURI(photo_url)+"&api_user_key=5******************************f&api_paste_name=cornered&api_paste_private=2&api_paste_expire_date=1W",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
onload: function(response) {
alert("posted " + response);
}
});
我在剧本中没有得到任何回应。要检查发布请求本身是否正常工作,我使用http://requestmaker.com/并显示POST请求返回302响应
请求标头已发送:
POST /post.php HTTP/1.1
Host: pastebin.com
Accept: */*
Content-Type: application/x-www-form-urlencoded
Content-Length: 152
响应标题:
HTTP/1.1 302 Moved Temporarily
Date: Wed, 10 Dec 2014 15:27:20 GMT
Content-Type: text/html
Transfer-Encoding: chunked
Connection: keep-alive
Set-Cookie: __cfduid=d61fd0544ec1b0c284ba908367557bc7f1418225240; expires=Thu, 10-Dec- 15 15:27:20 GMT; path=/; domain=.pastebin.com; HttpOnly
X-Powered-By: PHP/5.5.5
Set-Cookie: cookie_key=1; expires=Wed, 07-Jan-2015 15:27:20 GMT; Max-Age=2419200; path=/; domain=.pastebin.com
Set-Cookie: realuser=1; expires=Thu, 11-Dec-2014 15:27:20 GMT; Max-Age=86400; path=/
location: /index.php?e=2
Vary: Accept-Encoding
Server: cloudflare-nginx
CF-RAY: 196a7749d5c713e9-LAX
答案 0 :(得分:1)
将您的请求发送至http://pastebin.com/api/api_post.php
而不是http://pastebin.com/post.php
。