다음 코드를 사용하여 HTTP 헤더를 인쇄하고 있습니다. 이제HttpURLConnection이 모든 헤더를 반환하지 않습니다.
Key : null ,Value : [HTTP/1.1 200 OK]
Key : Accept-Ranges ,Value : [bytes]
Key : Cache-Control ,Value : [max-age=604800, public]
Key : Connection ,Value : [Keep-Alive]
Key : Date ,Value : [Mon, 03 Oct 2016 18:01:06 GMT]
Key : ETag ,Value : ["159eb4-53dce1f957880-gzip"]
Key : Expires ,Value : [Mon, 10 Oct 2016 18:01:06 GMT]
Key : Keep-Alive ,Value : [timeout=5, max=100]
Key : Last-Modified ,Value : [Sat, 01 Oct 2016 13:59:46 GMT]
Key : Server ,Value : [Apache/2.4.12 (Unix) OpenSSL/1.0.1e-fips mod_bwlimited/1.4]
Key : Transfer-Encoding ,Value : [chunked]
Key : Vary ,Value : [Accept-Encoding,User-Agent]
나는 컬을 통해 노력하고있어 다음 Content-Length
헤더는 자바 출력에서 누락되는 방법을
$ curl -v -D - http://example.com/example -o /dev/null
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Trying 111.111.111.111...
0 0 0 0 0 0 0 0 --:--:-- 0:00:01 --:--:-- 0* Connected to example.com (111.111.111.111) port 80 (#0)
> GET example.com/example HTTP/1.1
> Host: example.com
> User-Agent: curl/7.47.0
> Accept: */*
>
< HTTP/1.1 200 OK
HTTP/1.1 200 OK
< Date: Mon, 03 Oct 2016 18:25:11 GMT
Date: Mon, 03 Oct 2016 18:25:11 GMT
< Server: Apache/2.4.12 (Unix) OpenSSL/1.0.1e-fips mod_bwlimited/1.4
Server: Apache/2.4.12 (Unix) OpenSSL/1.0.1e-fips mod_bwlimited/1.4
< Last-Modified: Sat, 01 Oct 2016 13:59:46 GMT
Last-Modified: Sat, 01 Oct 2016 13:59:46 GMT
< ETag: "159eb4-53dce1f957880"
ETag: "159eb4-53dce1f957880"
< Accept-Ranges: bytes
Accept-Ranges: bytes
< Content-Length: 1416884
Content-Length: 1416884
< Cache-Control: max-age=604800, public
Cache-Control: max-age=604800, public
< Expires: Mon, 10 Oct 2016 18:25:11 GMT
Expires: Mon, 10 Oct 2016 18:25:11 GMT
< Vary: Accept-Encoding,User-Agent
Vary: Accept-Encoding,User-Agent
<
{ [1080 bytes data]
30 1383k 30 427k 0 0 116k 0 0:00:11 0:00:03 0:00:08 116k^C
참조 여기에
URL url = new Url("htttp://example.com/example");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
Map<String, List<String>> map = conn.getHeaderFields();
for (Map.Entry<String, List<String>> entry : map.entrySet()) {
System.out.println("Key : " + entry.getKey() +
" ,Value : " + entry.getValue());
}
출력입니까? 왜 이런 일이 생길까요? 이 문제를 어떻게 해결할 수 있습니까?
그것은 API를 통해 제공되는 것 :
이 내가 무엇을 얻을 수 있습니다. 수정 프로그램이없고 필요하지 않습니다. – EJP
@EJP 어떻게 수정해야합니까? 서버가'Content-Length'를 보내면 API가'Content-Length'를 반환하지 않아야합니까? –
내가 참조하는 API는'getContentLength()'(및'getContentLengthLong()')입니다. – EJP