小编cop*_*jon的帖子

使用来自.NET命令行应用程序的已签名Google Maps API地理编码请求

因此,当我导入记录时,我正在编写一个缓存地理编码数据的应用程序.当我使用未签名的请求时,我的工作正常,但是当我尝试使用我公司的clientid和签名时,我似乎无法弄清楚出了什么问题.我总是得到一个403 Forbidden.

这是我的URL构建器:

    private const string _googleUri = "http://maps.googleapis.com/maps/api/geocode/xml?address=";
    private const string _googleClientId = "XXXXXXXX";
    private const string _googleSignature = "XXXXXXXXXXXXXXXXXXXXXXXX";

//RESOLVED
    private static String GetGeocodeUri(string address)
    {
        ASCIIEncoding encoding = new ASCIIEncoding();
        string url = String.Format("{0}{1}&client={2}&sensor=false"
                                   , _googleUri
                                   , HttpUtility.UrlEncode(address)
                                   , _googleClientId);

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

        Uri uri = new Uri(url);
        byte[] encodedPathAndQueryBytes = encoding.GetBytes( uri.LocalPath …
Run Code Online (Sandbox Code Playgroud)

.net c# google-maps geocoding google-maps-api-3

6
推荐指数
2
解决办法
5695
查看次数

标签 统计

.net ×1

c# ×1

geocoding ×1

google-maps ×1

google-maps-api-3 ×1