【发布时间】:2020-10-28 17:15:45
【问题描述】:
我学到了很多在 Java 或其衍生版本中运行 curl 的建议。例如curl command in Java、using curl command in Java等。
另外,我已经知道如何fetch the metadata of a given resource using DOI。根据这条指令,我对使用 Java 中的小 sn-p 运行这个 curl 命令来处理结果非常感兴趣。
让我们举个例子。网址是http://dx.doi.org/10.1016/j.immuni.2015.09.001。
从终端运行 curl 命令
curl -LH "Accept: application/x-bibtex" http://dx.doi.org/10.1016/j.immuni.2015.09.001
输出看起来像
@article{Biswas_2015,
doi = {10.1016/j.immuni.2015.09.001},
url = {https://doi.org/10.1016%2Fj.immuni.2015.09.001},
year = 2015,
month = {sep},
publisher = {Elsevier {BV}},
volume = {43},
number = {3},
pages = {435--449},
author = {Subhra~K. Biswas},
title = {Metabolic Reprogramming of Immune Cells in Cancer Progression},
journal = {Immunity}
在 Groovy 中运行这个 curl 命令
回收本站分享的部分代码,我写了如下流程。
Map result = [:]
String command = "curl -LH 'Accept: application/x-bibtex' http://dx.doi.org/10.1016/j.immuni.2015.09.001"
Process process = Runtime.getRuntime().exec(command)
InputStream stream = process.getInputStream()
result.put("data", stream.text)
process.destroy()
我得到的是 HTML 中的整个页面,而不是我期望的 BibTeX 格式的表单。
问题是:我在这里做错了什么?有没有遇到过这个问题的人?
【问题讨论】:
标签: java curl groovy metadata doi