Javascript 使用localhost时无法上载到Imgur
我正在尝试将imgurapi实现到当前的web应用程序中,以上载和检索图像。我的应用程序在我的wamp64/www文件夹中,当我使用127.0.0.1/imgurTest.html或在本地访问文件时,代码似乎运行良好,但当我使用localhost/imgurTest.html运行它时,代码似乎不起作用。“我的控制台”上出现以下错误:Javascript 使用localhost时无法上载到Imgur,javascript,localhost,imgur,Javascript,Localhost,Imgur,我正在尝试将imgurapi实现到当前的web应用程序中,以上载和检索图像。我的应用程序在我的wamp64/www文件夹中,当我使用127.0.0.1/imgurTest.html或在本地访问文件时,代码似乎运行良好,但当我使用localhost/imgurTest.html运行它时,代码似乎不起作用。“我的控制台”上出现以下错误: Failed to load resource: net::ERR_HTTP2_PROTOCOL_ERROR Uncaught (in promise) TypeE
Failed to load resource: net::ERR_HTTP2_PROTOCOL_ERROR
Uncaught (in promise) TypeError: Failed to fetch
我在下面附上了我的HTML文件
<body>
<input type="file" id="file"><br>
<img id="img" height="300"><br>
<p id="url"></p>
<script>
const file = document.getElementById("file");
const url = document.getElementById("url");
file.addEventListener("change", ev => {
const formData = new FormData();
formData.append("image", ev.target.files[0]);
fetch("https://api.imgur.com/3/image", {
method: "post",
headers: {
Authorization: "Client-ID XXXXXXXX"
},
body: formData
}).then(data => data.json()).then(data => {
document.getElementById("img").src=data.data.link
url.innerText=data.data.link
})
})
</script>
</body>
我读了之后发现,Imgur可能会限制直接从localhost访问映像,我想知道是否有解决方法