[WPF] Image의 Source가 Uri일 경우 특수한 문제점 해결

<Window x:Class="WpfApplication2.Window1"
    xmlns
="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x
="http://schemas.microsoft.com/winfx/2006/xaml"
    Title
="Window1" Height="300" Width="300">
   
<Grid>
       
<Grid.ColumnDefinitions>
           
<ColumnDefinition />
            <
ColumnDefinition />
        </
Grid.ColumnDefinitions>
       
       
<Image x:Name="img1" Grid.Column="0" 
            Source
="http://sp1.mm-a4.yimg.com/image/2954925478" />
       
        <
Image x:Name="img2" Grid.Column="1"
            Source
="http://chaoskcuf.com/attach/1/1387427076.jpg" />

    </
Grid>
</Window>

위와 같은 코드는 보기에는 아무 문제가 없지만,
실행을 시켜보면 참 난감한 상황이 발생합니다.

사용자 삽입 이미지


http://sp1.mm-a4.yimg.com 이쪽 서버가 옛날 방식이고 무언가 비표준틱(?)한 구현을 해놓아서
그런지 아무래도 이미지가 보이질 않습니다.
http://sp1.mm-a4.yimg.com/image/2954925478 근데 이쪽 링크를 따라가서 웹브라우저에서
본다면 아무문제가 없이 잘 보입니다.


Procedure Code로 아래와 같이 구현을 하여도 역시 나오질 않습니다.

BitmapImage bitmap = new BitmapImage(new Uri("http://sp1.mm-a4.yimg.com/image/2954925478"));
img1.Source = bitmap;

가끔 Exception(ServerProtocolViolation)도 뿜어줄 때가 있습니다.


그럼 해결책은 있을까요?
사용자 삽입 이미지
일단 Application Configuration File을  App.config라는 이름으로 하나 추가한 다음

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
 
<system.net>
   
<settings>
     
<httpWebRequest useUnsafeHeaderParsing="true"   />
    </
settings>
 
</system.net>
</configuration>

위와 같이 useUnsafeHeaderParsing 값을 true 로 변경하시면 됩니다.
기본이 false이고 저 값이 false일 때는 아래와 관련된 http parsing 오류가 발생하면 Image 로드를 실패하게 됩니다.

  • In end-of-line code, use CRLF; using CR or LF alone is not allowed.

  • Headers names should not have spaces in them.

  • If multiple status lines exist, all additional status lines are treated as malformed header name/value pairs.

  • The status line must have a status description, in addition to a status code.

  • Header names cannot have non-ASCII chars in them. This validation is performed whether this property is set to true or false

  • chaoskcuf
    프로그래밍/TIP& Study 2007/09/04 09:51

    트랙백 주소 : http://chaoskcuf.com/trackback/109

    댓글을 달아 주세요

    Powerd by Textcube, designed by criuce
    rss