본문 바로가기

Silverlight

[삽질방지] 한글 URL 문제


이거 버그인지.. 

uri에서 자동으로 escape가 되는건지 이런 현상이 발생하네요.

             WebClient wc = new WebClient();
            wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(wc_DownloadStringCompleted);
//            string reqUrl = String.Format("http://localhost/song/searchresult?searchtitle={0}", HttpUtility.UrlEncode(searchWord.Text));
            string reqUrl = String.Format("http://localhost/song/searchresult?searchtitle={0}", HttpUtility.UrlEncode(HttpUtility.UrlEncode(searchWord.Text)));
            Uri loaduri = new Uri(reqUrl, UriKind.Absolute);

            wc.DownloadStringAsync(loaduri);           

searchWord.Text="씨야 2집" 이라고 할 때,

위와 같이 URL에서 JSON데이터를 받아와서 뿌리려고 하는데, 빨간 색처럼 하니까

실제로 통신할때 쿼리는 http://localhost/song/searchresult?searchtitle=씨야 2집<-- 이렇게 다시 unescape되서 날라가네요.

그래서, 초록색처럼 UrlEncode한 것을 한번 더 해서 보내보니까 정상적으로 통신이 됩니다.

참조하시길.