我有一个 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/