내가 이렇게 원격 이미지의 다운로드 크기 제한 할 수 있도록 원격 파일의 내용 길이를 얻을하려고 해요 :원격 파일의 올바른 내용 길이를 가져옵니다
WebResponse response = this.GetWebRequest().GetResponse();
long contentLength = response.ContentLength;
// WebResponse.ContentLength doesn't always know the value,
// it returns -1 in this case.
if (contentLength == -1)
{
// Response headers may still have the Content-Length inside of it.
string headerContentLength = response.Headers["Content-Length"];
if (!String.IsNullOrWhiteSpace(headerContentLength))
{
contentLength = long.Parse(headerContentLength,
CultureInfo.InvariantCulture);
}
}
내 문제가 있다는 것입니다을 content-length 헤더는 선택 사항이기 때문에 때때로 그 값은 결정할 수 없습니다.
here 및 here 나는 길이를 결정하기 위해 Transfer-Encoding = 청크 된 속성을 어떻게 든 사용할 수 있지만 그 방법에 대한 예는 발견하지 못했음을 나타내는 것처럼 보입니다.
이것이 가능합니까? 누구든지 코드 예제를 제공 할 수 있습니까?
선택 사항입니다. (거의 항상 이미지가 있다고 가정 할지라도) 모든 경우에이 값을 결정할 수는 없습니다. – BrokenGlass
@BrokenGlass 필자는 그렇게 생각했지만 디버깅과 파이어 버그 검사는 그렇지 않은 것으로 나타났습니다. 내가 특별히보고있는 이미지는 다음과 같습니다. http://images.mymovies.net/images/film/cin/500x377/fid10122.jpg –
@James South : 응답에 'Content-Length : 33566'이 표시됩니다. 해당 특정 URL : http://hurl.it/hurls/c79a3f4611819c370e53a30d07958ee1892862b9/ce4aba5e6c9029ed454632536404f2496544c6b0 – Piskvor