对服务器的一个简单的请求就是提供一些问题,这是url,
https://dc2-vault.myvzw.com/dv/api/user/c107a6db69104a10bc247a28fb81131e/search?query=contentType:audio/*和(如'RoyalJatt.Com‘)&sort=name+asc&start=1&count=2147483647
然后我就这么做
url = Uri.EscapeUriString(url);我明白了,
https://dc2-vault.myvzw.com/dv/api/user/c107a6db69104a10bc247a28fb81131e/search?query=contentType:audio/*%20AND%20(genre%20like%20'RoyalJatt.Com%20)')&sort=name+asc&start=1&count=2147483647
问题是这个,
查询查找一个类型为RoyalJatt.Com%20的文件,该文件应该是RoyalJatt.Com%20%29
出于某种原因,它省略了")“
我能做些什么来解决这个问题?
发布于 2015-04-14 05:01:15
这是我所做的,并使它发挥作用。
private readonly static string reservedCharacters = "!\*'();:@&=+$,/?%#[]";` //Neither of Uri.EscapeUriString and Uri.EscapeDataString methods encodes //the RFC 2396 unreserved characters If you need these encoded then you //will have to manually encode them public static string UrlEncode(string value) { if (String.IsNullOrEmpty(value)) return String.Empty; var sb = new StringBuilder(); foreach (char @char in value) { if (reservedCharacters.IndexOf(@char) == -1) sb.Append(@char); else sb.AppendFormat("%{0:X2}", (int)@char); } return sb.ToString(); }
发布于 2015-04-13 21:01:02
好的,看来在url中使用的编码数据与对url的编码不一样!
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
namespace Model_Library
{
    [TestClass]
    public class test
    {
        [TestMethod]
        public void test2()
        {
            string url = @"https://dc2-vault.myvzw.com/dv/api/user/c107a6db69104a10bc247a28fb81131e/";
            string data = @"search?query=" + Uri.EscapeDataString(@"contentType:audio/* AND (genre like 'RoyalJatt.Com )')") + @"&sort=name+asc&start=1&count=2147483647";
            string enc = Uri.EscapeUriString(url) + data;
            Console.Write(enc);
        }
    }
}https://stackoverflow.com/questions/29614835
复制相似问题