java - 仅获取响应代码而不是 url 的完整来源

标签 java http url

我有一个 URL,我只想检查页面的响应代码,而不是完整的页面源,因为获取完整的页面源非常慢。什么是正确的方法?

HttpUrlConnection 中的 getResponseCode() 获取完整的页面源还是仅获取标题?

最佳答案

直接来自文档,HttpUrlConnection#getResponseCode()

Gets the status code from an HTTP response message. For example, in the case of the following status lines: HTTP/1.0 200 OK HTTP/1.0 401 Unauthorized

It will return 200 and 401 respectively. Returns -1 if no code can be discerned from the response (i.e., the response is not valid HTTP).

关于java - 仅获取响应代码而不是 url 的完整来源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17101480/

相关文章:

http - Cookies 在 Firefox 和 Chrome 中工作,不适用于 IE9

android - 客户端(手机)如何拦截和修改http响应

jquery - WordPress - 一页导航

php - 在PHP中存储上一页的URL?

java - 从 Firebase 下载文件 |应用程序可以在 Debug模式下运行,但不能在 Release模式下运行

java - java中获取状态码的正则表达式是什么?

java - 如何在不生根的情况下以编程方式截取应用程序相机表面 View 和图像叠加的屏幕截图?

java - 如何在 Java 中快速检索目录列表?

http - WADL 应用程序?

html - 如何使用文件 : scheme? 在 html 中指定本地文件