2013-05-29 20 views
2

我寫了一個TIdHTTPServer Web服務器。印版是10,德爾福是2007年Indy TIdHTTPResponseInfo.ContentType未設置

我用下面的代碼發回JPEG,GIF,PNG等,文件:

 AResponseInfo.ServeFile(AContext,rootpath+ARequestInfo.document); 
     AResponseInfo.ContentType := 'image/jpeg'; 
     AResponseInfo.ContentType := GetMimeTypeFromFile('.'+ExtractFileDir(rootpath+ARequestInfo.document)); 

的圖像在所有瀏覽器中正確顯示。但我看到(通過Chrome中的控制檯)它們以MIME類型返回:text/html。 我試過圖片/ jpegGetMIMTypeFromFile方法並且都產生文本/ html。

是否有另一個電話我必須做?我在其他線程看到調用AResponseInfo.WriteHeader函數。但是,當添加它會引發一個異常,標題被寫入兩次。

回答

3

其實發現了這個問題。需要指定內容類型之前的 ServeFile調用。

AResponseInfo.ContentType := 'image/jpeg'; 
    AResponseInfo.ServeFile(AContext,rootpath+ARequestInfo.document);