This is my java code. I use input stream from connection to calculate response data’s byte size. The output is 20239.
try {
URI uri = new URI("http://google.com");
HttpURLConnection connection = (HttpURLConnection) uri.toURL().openConnection();
connection.setRequestMethod("GET");
int response_code = connection.getResponseCode(); // Triggers the request
if(response_code == HttpURLConnection.HTTP_OK){
InputStream inputStream = connection.getInputStream();
byte[] data = new byte[1024];
int bytesRead = 0;
int totalBytesRead = 0;
while((bytesRead = inputStream.read(data, 0, data.length)) != -1)
totalBytesRead += bytesRead;
System.out.println(totalBytesRead);
}
}
catch (Exception e) {
e.printStackTrace();
}
This is the response I got from curl command
curl -I http:// google.com
Notice that the Content-Length is 219
curl: (3) URL rejected: No host part in the URL
HTTP/1.1 301 Moved Permanently
Location: http://www.google.com/
Content-Type: text/html; charset=UTF-8
Content-Security-Policy-Report-Only: object-src 'none';base-uri 'self';script-src 'nonce-doPfSl2PozXZr4JpEDRdfA' 'strict-dynamic' 'report-sample' 'unsafe-eval' 'unsafe-inline' https: http:;report-uri https://csp.withgoogle.com/csp/gws/other-hp
Date: Fri, 31 May 2024 07:34:30 GMT
Expires: Sun, 30 Jun 2024 07:34:30 GMT
Cache-Control: public, max-age=2592000
Server: gws
Content-Length: 219
X-XSS-Protection: 0
X-Frame-Options: SAMEORIGIN
Why is the value different?
1