我有一个包含URL看起来像这样的字符串:如何编码URL字符串
http://www.test.com/images/tony的pics.jpg
我需要的URL看起来像这样:
http://www.test.com/images/tony%27s%20pics.jpg
我该如何以编程方式解决这个与STRING形式的网址。谢谢。
我有一个包含URL看起来像这样的字符串:如何编码URL字符串
http://www.test.com/images/tony的pics.jpg
我需要的URL看起来像这样:
http://www.test.com/images/tony%27s%20pics.jpg
我该如何以编程方式解决这个与STRING形式的网址。谢谢。
我认为这很容易通过使用HttpUtility以UrlEncode来解决:
string url = "http://www.test.com/images/" + HttpUtility.UrlEncode("tony's pics.jpg");
这会导致http%3a%2f%2fwww.google.com%2fsearch%3fq%3d示例 – Mob
您是对的,已编辑修复。 – ptfaulkner
有获取HttpServerUtility一脸at UrlEncode:
HttpServerUtility.UrlEncode("http://www.test.com/images/tony's pics.jpg");
这将导致http%3a%2f%2fwww.google.com%2fsearch%3fq%3dExample – Mob
这里看到这个答案http://stackoverflow.com/questions/575440/url-encoding-using-c-sharp/575843#575843 – Mob
Dupe of http://stackoverflow.com/questions/1461223/how-do-i-encode-an-url? – Robert