我正在使用pCloud Api从请求中获得下载链接。这是GET请求。当我请求表单浏览器时,我可以得到响应。但是当我使用jQuery时,我会得到一个响应代码result : 7010
Api请求URL:https://api.pcloud.com/getpublinkdownload?code=8eM7
当我从浏览器请求时,我得到了这个响应:
{
"result": 0,
"expires": "Mon, 07 Aug 2017 00:12:50 +0000",
"dwltag": "aftsTab2SLkC4MDXRdp6Am",
"path": "\/cBZkvG2cXZNPjykVZZZChTDE7ZNVZZj5JZkZSqfRZIXZqkZmVZR7Zd7Z4ZfkZIZyVZokZbXZ3VZFkZ77ZIgCcZ14l5zXbx6p4GwdeEPdF1707nIPm7\/image%20%286%29.jpg",
"hosts": [
"p-def2.pcloud.com",
"c166.pcloud.com"
]
}我需要这个hosts和path来生成下载链接。我只需要这个-https://c166.pcloud.com/cBZkvG2cXZNPjykVZZZChTDE7ZNVZZj5JZkZSqfRZIXZqkZmVZR7Zd7Z4ZfkZIZyVZokZbXZ3VZFkZ77ZIgCcZ14l5zXbx6p4GwdeEPdF1707nIPm7/image%20%286%29.jpg
我必须使用jQuery/JavaScript来获得这个响应。我尝试了PHP,它可以工作,但这个链接只会形成您请求的ip地址。所以,我必须使用JQ/JS。
我的守则:
$(document).ready(function(){
function httpGet(theUrl){
var xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", theUrl, false ); // false for synchronous request
xmlHttp.send( null );
return xmlHttp.responseText;
}
console.log(httpGet("https://api.pcloud.com/getpublinkdownload?code=8eM7"));
});谢谢你帮我。
发布于 2017-08-06 19:46:18
pCloud服务器似乎正在检查推荐程序。在大多数情况下,服务器将拒绝来自自身的访问。
只有来自一小部分经批准的(登录)页面的浏览器才能访问;这有利于referer的一组合作付费站点之间的材料共享。
在随后的html中,脚本成功地运行并获得了图像url,但是浏览器在试图加载图像时会引发错误。
<html>
<head>
</head>
<script
src="http://code.jquery.com/jquery-3.2.1.js"
integrity="sha256-DZAnKJ/6XZ9si04Hgrsxu/8s717jcIzLy3oi35EouyE="
crossorigin="anonymous"></script>
<body>
<h1>Load Image from pCloud </h1>
<img class="loading">
<script>
$(document).ready(function() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
if (this.responseText){
var host = JSON.parse(this.responseText).hosts[0];
var path = JSON.parse(this.responseText).path;
}
$(".loading").attr("src", "https://" + host + path);
}
};
xhttp.open("GET", "https://api.pcloud.com/getpublinkdownload?code=8eM7", true);
xhttp.send();
});
</script>
</body>
</html>https://stackoverflow.com/questions/45535199
复制相似问题