如何在Java中使用cURL? [英] How to use cURL in Java?
问题描述
我是java的新手,想在java中使用curl。我的问题是curl内置在java或我必须从任何第三方来源安装使用Java。如果是这样,如何在java中安装curl。我一直在谷歌搜索了很长时间,但没有找到任何帮助。希望任何人都可以帮助我在那里。
I am a newbie in java and wanted to use curl in java. What is my question is curl built-in in java or I have to install it from any 3rd party source to use with Java. If so, how to install curl in java. I have been googling for a long time but didnt find any help. Hope anyone can help me out there.
提前感谢。
推荐答案
a href =http://docs.oracle.com/javase/6/docs/api/java/net/URL.html =noreferrer> java.net.URL
和/或 java.net.URLConnection
。
You can make use of java.net.URL
and/or java.net.URLConnection
.
URL url = new URL("http://stackoverflow.com");
try (BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream(), "UTF-8"))) {
for (String line; (line = reader.readLine()) != null;) {
System.out.println(line);
}
}
另请参阅 Oracle的简单教程。这是一个有点冗长。要使用较少详细的代码,您可以考虑 Apache HttpClient
Also see the Oracle's simple tutorial on the subject. It's however a bit verbose. To end up with less verbose code, you may want to consider Apache HttpClient instead.
顺便说一下:如果你的下一个问题是如何处理HTML结果?,那么答案是使用HTML解析器。不,不要使用正则表达式。。
By the way: if your next question is "How to process HTML result?", then the answer is "Use a HTML parser. No, don't use regex for this.".
- Using java.net.URLConnection to fire and handle HTTP requests
- What are the pros and cons of the leading Java HTML parsers?
这篇关于如何在Java中使用cURL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!