相当于 Java 中 .NET 的 WebClient 和 HttpWebRequest?

发布于 2024-07-26 23:27:29 字数 408 浏览 5 评论 0原文

.NET 有 HttpWebRequestWebClient 用于模拟浏览器请求的类。

我会用谷歌搜索,但我不知道该使用什么关键字。

我想编写在小程序或本地 .jar 中执行 HTTP GET 和 POST 以及 cookie 的代码,并以文本字符串或其他可解析结构的形式返回响应。

.NET has the HttpWebRequest and WebClient classes for simulating a browser's requests.

I'd google it, but I'm not sure what keyword to use.

I want to write code that does does HTTP GETs and POSTs, along with cookies, in an applet or local .jar and gives me back the response in a text string or some other parseable structure.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

沧桑㈠ 2024-08-02 23:27:29

HttpURLConnection< /a> 相当于 Java 中的 HttpWebRequest

URL iurl = new URL(url);
HttpURLConnection uc = (HttpURLConnection)iurl.openConnection();
uc.connect();
if (uc.getContentType().equalsIgnoreCase("image/jpeg"))
{
  result = true;
}

HttpURLConnection is Java's equivalent of HttpWebRequest.

URL iurl = new URL(url);
HttpURLConnection uc = (HttpURLConnection)iurl.openConnection();
uc.connect();
if (uc.getContentType().equalsIgnoreCase("image/jpeg"))
{
  result = true;
}
盗心人 2024-08-02 23:27:29

Apache HTTPClient 具有相同的功能,但 API 并不完全相同。 Oakland Software 有一个表格将其商业产品与各种替代品(包括 Apache 产品)进行比较。 Apache 对内置 HttpUrlConnection 的看法(引用自上面的链接页面)是:

jdk有HttpUrlConnection
这在很多方面都是有限的
有缺陷。

以下是 HTTPClient 教程 的链接。

Apache HTTPClient has equivalent functionality, though the APIs are not exactly the same. Oakland Software has a table comparing their commercial product with various alternatives, including the Apache product. Apache's own opinion of the built-in HttpUrlConnection (quoted from the above linked-to page) is:

The jdk has the HttpUrlConnection
which is limited and in many ways
flawed.

Here's a link to the HTTPClient tutorial.

短叹 2024-08-02 23:27:29

html 单元对我来说。
我可以模拟javascript(在一定程度上)

html unit for me.
i can simulate javascript (to a certain extent)

ゃ人海孤独症 2024-08-02 23:27:29

验证 Apache Cx JaxRs 库中的 Webclient。

结帐这个:
https://cxf.apache.org/javadoc /latest/org/apache/cxf/jaxrs/client/WebClient.html

示例代码如下:

WebClient client = WebClient.create(url);
client.path(ADD_PATH).path("/books/2").accept("text/plain");
s = client.get(String.class);
System.out.println(s);

Verify Webclient in Apache Cx JaxRs Library.

Checkout this:
https://cxf.apache.org/javadoc/latest/org/apache/cxf/jaxrs/client/WebClient.html

Sample code looks below:

WebClient client = WebClient.create(url);
client.path(ADD_PATH).path("/books/2").accept("text/plain");
s = client.get(String.class);
System.out.println(s);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文