2010-12-30 2 views
0

작동하지 않습니다 다음과 같이 나는 그것을 확장하고 기본 WebRequest 클래스를 변경이는 이제 DownloadProgressChanged 이벤트는 제외하고, 잘 작동WebClient.DownloadProgressChanged는 Gzip으로

protected override WebRequest GetWebRequest(Uri address) 
{ 
    var req = base.GetWebRequest(address) as HttpWebRequest; 
    req.AutomaticDecompression = DecompressionMethods.GZip; 
    return req; 
} 

Content-Length 헤더가 서버에 의해 적절하게 설정 되었어도 (서버가 응답을 청취하지 않음) 발사하지 않습니다.

왜 이런가요?

EDIT : 실제로 DownloadProgressChanged 이벤트가 발생하지만 다운로드가 완료 될 때까지 100이 표시 될 때까지 항상 0의 백분율을 표시합니다.이 동작의 원인은 무엇입니까?

+0

HTTPS를 사용하고 있습니까? 때로 Content-Lengh가 암호화되어 브라우저가 직접 알 수 없게됩니다. – turtlepick

+0

HTTPS가 사용되지 않습니다. – yclevine

답변

0

음, 나도 잘 모르겠지만,이 모든 것을 구현하지 않았다는 것을 알 수 있습니다. 아마 thats 왜 ... 당신은 헤더가 누락되었을 수 있습니다. 리플렉터는 좀 더 많은 코드를 보여줍니다. 어쩌면이 방법의 두 번째 줄이 필요할 것입니다.

protected virtual WebRequest GetWebRequest(Uri address) 
{ 
    WebRequest request = WebRequest.Create(address); 
    this.CopyHeadersTo(request); 
    if (this.Credentials != null) 
    { 
     request.Credentials = this.Credentials; 
    } 
    if (this.m_Method != null) 
    { 
     request.Method = this.m_Method; 
    } 
    if (this.m_ContentLength != -1L) 
    { 
     request.ContentLength = this.m_ContentLength; 
    } 
    if (this.m_ProxySet) 
    { 
     request.Proxy = this.m_Proxy; 
    } 
    if (this.m_CachePolicy != null) 
    { 
     request.CachePolicy = this.m_CachePolicy; 
    } 
    return request; 
} 
+0

나는 base.GetWebRequest()를 호출하므로 모든 것을 처리 할 수 ​​있습니다. 어떤 경우 든 양측의 모든 헤더가 올바르게 전송됩니다. 유일한 문제는 다운로드 진행 상황입니다. – yclevine

관련 문제