开发者

System.Net.HttpUtility.HtmlEncode not encoding #

开发者 https://www.devze.com 2023-03-23 12:25 出处:网络
I need to encode a url in my WP7 application. The class im using do开发者_StackOverflow社区sent seem to encode # (to %23). Any ideas what im doing wrong?

I need to encode a url in my WP7 application. The class im using do开发者_StackOverflow社区sent seem to encode # (to %23). Any ideas what im doing wrong?

string foo = InkBunnyUrls.Login + "&username=" + txtUsername.Text + "&password=" + txtPassword.Password;
//foo = https://inkbunny.net/api_login.php?output_mode=xml&username=test&password=foobar#1
string url = System.Net.HttpUtility.HtmlEncode(foo);
// url = https://inkbunny.net/api_login.php?output_mode=xml&username=test&password=foobar#1

Edit: I tried UrlEncode and that dosent work (see below). Reading the msdn doc it wont escape # . I cant use the system.web class as it isnt in WP7

        string foo = InkBunnyUrls.Login + "&username=" + txtUsername.Text + "&password=" + txtPassword.Password;
        //foo = https://inkbunny.net/api_login.php?output_mode=xml&username=test&password=foobar#1
        string url = Uri.EscapeUriString(foo);
        //  https://inkbunny.net/api_login.php?output_mode=xml&username=test&password=foobar#1


The # symbol doesn't need to be HTML-encoded.

If you're expecting the result to be %23 then you should look at UrlEncode instead:

string encoded = HttpUtility.UrlEncode("#");    // "%23"

EDIT...

Do the WP7 libs support EscapeDataString?

string encoded = Uri.EscapeDataString("#");    // "%23"


I think you are looking for UrlEncode and not HtmlEncode.

0

精彩评论

暂无评论...
验证码 换一张
取 消