因此,当我导入记录时,我正在编写一个缓存地理编码数据的应用程序.当我使用未签名的请求时,我的工作正常,但是当我尝试使用我公司的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)