gpt4 book ai didi

Java HTTP 请求 : get content size

转载 作者:太空宇宙 更新时间:2023-11-04 06:13:57 24 4
gpt4 key购买 nike

我想知道是否可以通过http请求获取网页的大小。

我用它来获得预言机页面长度:

URL oracle = new URL("http://www.oracle.com/");
URLConnection yc = oracle.openConnection();
List<String> get = yc.getHeaderFields().get("content-Length");

但是当我将其用于 Google 页面时,标题中没有内容长度。

最佳答案

您必须使用正确的大写或小写。字段名称是 Content-Length 而不是 content-Length。您还可以使用 URLConnection 对象getContentLength() 方法。任何需要发送 HTTP 正文的应用程序都应该使用此字段,Google 就是这样做的。

请注意,Google 使用安全连接。

关于Java HTTP 请求 : get content size,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28345525/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com