Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# .Net网站管理员API对URL的编码不正确(Google.API.Webmasters.v3)_C#_.net_Google Api Dotnet Client - Fatal编程技术网

C# .Net网站管理员API对URL的编码不正确(Google.API.Webmasters.v3)

C# .Net网站管理员API对URL的编码不正确(Google.API.Webmasters.v3),c#,.net,google-api-dotnet-client,C#,.net,Google Api Dotnet Client,我一直在努力让新的API正常工作。我在执行查询时经常遇到以下错误: 分析NaN值时出错。路径“”,第0行,位置0 根据调查,我认为.Net代码未对斜杠(/)进行编码,从而对请求中的URL进行了错误编码。这会更改请求URL路径并导致404错误 如果从请求的{site}部分省略http://部分,它将起作用。e、 g.domain.com非 如果您使用https站点,则没有解决方法。您也不能发出任何要求您在主页外传递特定URL的请求,因为它需要包含斜杠(/)。我在Google Geocode API

我一直在努力让新的API正常工作。我在执行查询时经常遇到以下错误:

分析NaN值时出错。路径“”,第0行,位置0

根据调查,我认为.Net代码未对斜杠(/)进行编码,从而对请求中的URL进行了错误编码。这会更改请求URL路径并导致404错误

如果从请求的{site}部分省略http://部分,它将起作用。e、 g.domain.com


如果您使用https站点,则没有解决方法。您也不能发出任何要求您在主页外传递特定URL的请求,因为它需要包含斜杠(/)。

我在Google Geocode API中就是这样做的。不确定这是否对你有帮助,但希望你能理解

public static string Sign(string url, string keyString)
        {
            ASCIIEncoding encoding = new ASCIIEncoding();

            // converting key to bytes will throw an exception, need to replace '-' and '_' characters first.
            string usablePrivateKey = keyString.Replace("-", "+").Replace("_", "/");
            byte[] privateKeyBytes = Convert.FromBase64String(usablePrivateKey);

            Uri uri = new Uri(url);
            byte[] encodedPathAndQueryBytes = encoding.GetBytes(uri.LocalPath + uri.Query);

            // compute the hash
            HMACSHA1 algorithm = new HMACSHA1(privateKeyBytes);
            byte[] hash = algorithm.ComputeHash(encodedPathAndQueryBytes);

            // convert the bytes to string and make url-safe by replacing '+' and '/' characters
            string signature = Convert.ToBase64String(hash).Replace("+", "-").Replace("/", "_");

            // Add the signature to the existing URI.
            return uri.Scheme + "://" + uri.Host + uri.LocalPath + uri.Query + "&signature=" + signature;
        }

这就是我在GoogleGeocodeAPI中所做的。不确定这是否对你有帮助,但希望你能理解

public static string Sign(string url, string keyString)
        {
            ASCIIEncoding encoding = new ASCIIEncoding();

            // converting key to bytes will throw an exception, need to replace '-' and '_' characters first.
            string usablePrivateKey = keyString.Replace("-", "+").Replace("_", "/");
            byte[] privateKeyBytes = Convert.FromBase64String(usablePrivateKey);

            Uri uri = new Uri(url);
            byte[] encodedPathAndQueryBytes = encoding.GetBytes(uri.LocalPath + uri.Query);

            // compute the hash
            HMACSHA1 algorithm = new HMACSHA1(privateKeyBytes);
            byte[] hash = algorithm.ComputeHash(encodedPathAndQueryBytes);

            // convert the bytes to string and make url-safe by replacing '+' and '/' characters
            string signature = Convert.ToBase64String(hash).Replace("+", "-").Replace("/", "_");

            // Add the signature to the existing URI.
            return uri.Scheme + "://" + uri.Host + uri.LocalPath + uri.Query + "&signature=" + signature;
        }

正在此处跟踪此问题:


它与使用.Net 4.0有关,可以通过升级到.Net 4.5来修复此问题。此问题正在此处跟踪:


它与使用.Net 4.0有关,可以通过升级到.Net 4.5来修复,可能与之相关,或者@DaImTo#534就是其中之一。所以这是一个已知的错误。谢谢。这是一个开源项目,所以欢迎您修复它。如果您有任何问题,请发表评论,我会看看我是否能提供帮助。谢谢。我的visual studio版本太旧,无法打开项目(2010)。我可能升级到2015社区。据我所知,这将无论如何解决问题(.NET4.5似乎解决了这个bug)。可能与@DaImTo有关,或者@DaImTo#534就是其中之一。所以这是一个已知的错误。谢谢。这是一个开源项目,所以欢迎您修复它。如果您有任何问题,请发表评论,我会看看我是否能提供帮助。谢谢。我的visual studio版本太旧,无法打开项目(2010)。我可能升级到2015社区。据我所知,它无论如何都能解决这个问题(.NET4.5似乎能解决这个问题)。