0

Windows Phone の開発で、以下のコードで utf8 エンコードされた URI を作成したいのですが失敗しました。結果はまだユニコードですが、%D6%DC の形式ではありません...

        byte[] unicodeBytes = Encoding.Unicode.GetBytes(str);
        byte[] utf8bytes = Encoding.Convert(Encoding.Unicode, Encoding.UTF8, unicodeBytes);
        char[] utf8Chars = new char[Encoding.UTF8.GetCharCount(utf8bytes, 0, utf8bytes.Length)];
        Encoding.UTF8.GetChars(utf8bytes, 0, utf8bytes.Length, utf8Chars, 0);
        string utf8string = new string(utf8Chars);
        var URI = new Uri("http://www.jpwy.net/gc/search.php?" + utf8string);

これの何が問題なのですか?

4

1 に答える 1

2

あなたの目的はわかりませんが、文字列をエンコードするために HttpUtility.UrlEncode を使用しない理由はありますか? Urlencode のデフォルトのエンコーディングは UTF8 です。

上記のコードを次のように置き換えることができるはずです

var URI = new Uri("http://www.jpwy.net/gc/search.php?" + HttpUtility.UrlEncode(str));
于 2013-03-10T07:07:33.443 に答える