CrossRef Search API(docs here)提供来自DOI标识符的引用信息。我tried使用它来获得这个信息,但奇怪地得到404响应。CrossRef Search API是否支持跨域请求?
我设置的标头是
Content-type: application/json
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, POST, OPTIONS
Access-Control-Allow-Headers: Content-Type
Access-Control-Max-Age: 86400
我得到相同的结果,从this appspot tester,所以我不认为这是我的代码。
任何人都可以告诉我如何才能得到它的工作?它在自己的领域工作得很好。
可能他们根本不允许跨域,但我不确定是否/如何检查。
重复的例子:
function doiInfo(doi) {
var doienc = encodeURIComponent(doi);
var doiXHR;
window.XMLHttpRequest ? doiXHR=new XMLHttpRequest() : doiXHR=new ActiveXObject("Microsoft.XMLHTTP");
doiXHR.onreadystatechange=function()
{
if (doiXHR.readyState==4 && doiXHR.status==200)
{
console.log(doiXHR.responseText);
} else if (doiXHR.readyState==4) {
// something went wrong
}
}
doiXHR.open("GET", "http://search.crossref.org/dois?q=" + doienc, true);
doiXHR.setRequestHeader("Content-type", "application/json;");
doiXHR.setRequestHeader("Access-Control-Allow-Origin", "*");
doiXHR.setRequestHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
doiXHR.setRequestHeader("Access-Control-Allow-Headers", "Content-Type");
doiXHR.setRequestHeader("Access-Control-Max-Age", "86400"); // cache for 1 day
// doiXHR.withCredentials = "true";
doiXHR.send();
}
doiInfo('10.1002/bies.201000071')
在浏览器控制台从crossref.org
我得到
[
{
"doi": "http://dx.doi.org/10.1002/bies.201000071",
"score": 18.623272,
"normalizedScore": 100,
"title": "The phage-host arms race: Shaping the evolution of microbes",
"fullCitation": "Adi Stern, Rotem Sorek, 2010, 'The phage-host arms race: Shaping the evolution of microbes', <i>BioEssays</i>, vol. 33, no. 1, pp. 43-51",
"coins": "ctx_ver=Z39.88-2004&rft_id=info%3Adoi%2Fhttp%3A%2F%2Fdx.doi.org%2F10.1002%2Fbies.201000071&rfr_id=info%3Asid%2Fcrossref.org%3Asearch&rft.atitle=The+phage-host+arms+race%3A+Shaping+the+evolution+of+microbes&rft.jtitle=BioEssays&rft.date=2010&rft.volume=33&rft.issue=1&rft.spage=43&rft.epage=51&rft.aufirst=Adi&rft.aulast=Stern&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&rft.genre=article&rft.au=Adi+Stern&rft.au=+Rotem+Sorek",
"year": "2010"
}
]
从我的网站上运行它(不是HTTPS)我得到
OPTIONS http://search.crossref.org/dois?q=10.1002%2Fbies.201000071 404(未找到) XMLHttpRequest无法加载http://search.crossref.org/dois?q=10.1002%2Fbies.201000071。无效的HTTP状态代码404
的GET
/OPTIONS
问题之外,它肯定似乎到页面上,这似乎并没有对上获得404。
我想你可以用iframe和window.postMessage
(?)解决它,但听起来很乱。
请评论,如果我可以提供更多的细节,我会很高兴,似乎没有任何人在网上做过这个 - 希望不是因为这是不可能的!