我学到了很多curl
在 Java 或其衍生产品中运行的建议。例如,Java 中的 curl 命令,Java中使用 curl 命令等。
此外,我已经弄清楚如何使用 DOI 获取给定资源的元数据。从这个指令中,我对使用 Java 中的一个小片段来运行这个 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 格式的表单。
问题是:我在这里做错了什么?你们有没有遇到过这个问题?