Imgur API偶尔403禁止
Imgur API occasional 403 Forbidden?
在尝试远程上传到imgur时,偶尔会出现以下错误:加载资源失败:服务器响应状态为403(禁止)。但不是所有的时间,这是可疑的。
这是我的代码:
/* Drag and drop */
window.ondragover = function(e) {
e.preventDefault();
};
window.ondrop = function(e) {
e.preventDefault();
upload(e.dataTransfer.files[0]);
};
function upload(file) {
document.getElementById("view1").style.display = "none";
document.getElementById("loading").style.display = "inline";
var imageLink = "";
/* Is the file an image? */
if (!file || !file.type.match(/image.*/)) return;
document.body.className = "uploading";
var fd = new FormData();
fd.append("image", file); // Append the file
fd.append("key", "6528448c258cff474ca9701c5bab6927"); // The key
var xhr = new XMLHttpRequest();
xhr.open("POST", "http://api.imgur.com/2/upload.json");
xhr.onload = function() {
var link = JSON.parse(xhr.responseText).upload.links.imgur_page;
document.getElementById("loading").style.display = "none";
document.querySelector("#link").href = link;
document.querySelector("#link").innerHTML = link;
var imageLink = ""+document.querySelector("#link").innerHTML.replace("http://imgur.com/", "http://i.imgur.com/")+".jpg";
/* Image Preview */
document.getElementById("result").style.display = "inline";
document.getElementById("link-to-image").style.background = "url(" + imageLink + ") center center no-repeat";
document.body.className = "uploaded";
};
/* Send the formdata */
xhr.send(fd);
/* Remove the button */
document.getElementById("button").remove();
};
答案很简单-在短时间内发生了太多请求,Imgur正在阻止其中一些请求。我想商业客户的情况并非如此。
相关文章:
- 偶尔结结巴巴地说“;堆叠的”;translate()上的转换(v4.0.0-alpha40)
- 当我在form_for中的text_field_tag中点击Enter时,如何禁止发出POST请求
- 如何禁止使用'简明方法'使用esint
- 当所有输入文本字段都为空时,禁止表单提交,但当jquery中的任何字段不为空时允许提交
- 如何禁止在纯JavaScript形式输入的表单中输入特定字符
- 为什么PHP MySQL INSERT通过AJAX调用只是偶尔发生
- 在JS Metro应用程序中,禁止登录屏幕进行基本身份验证
- JSON偶尔未定义-我该如何检查
- 为什么新js Fetch标准禁止响应头名称为'设置Cookie 1/2'
- Javascript:可驱动api出现禁止的错误
- 运行一次函数,然后在 5 秒内禁止进一步调用
- jqGrid - 在右键单击时禁止选择行
- 正确禁止显示数据表中的警告
- 禁止用户刷新页面
- 拖放区.js禁止从服务器检索时的进度条
- AngularJS摘要周期偶尔无法更新范围
- 如何在angularjs应用程序中注销后,通过浏览器后退按钮禁止用户访问上一页
- 创建随机图像交换并禁止鼠标悬停事件
- 如何禁止html表单在提交时导航
- Imgur API偶尔403禁止