url - 为什么 Google 不支持查询字符串中包含 & 的有效网址?

标签 url url-encoding google-maps-static-api

尝试使用 W3C 验证器验证以下 HTML 将抛出 3 个错误(截至 2013 年 10 月 30 日):

<!DOCTYPE html>
<head><title>asdf</title></head>
<img src="http://maps.googleapis.com/maps/api/staticmap?zoom=13&size=279x183&markers=50.916780,5.347420&sensor=false" alt="map">

这 3 个错误都是相同的:

& did not start a character reference. (& probably should have been escaped as &.)

不幸的是,这里遵守 W3C 将导致静态 map 图像无法渲染。尝试嵌入 img 标记,并将以下 URL 作为其 src 属性的值:

<img src="http://maps.googleapis.com/maps/api/staticmap?zoom=13&amp;size=279x183&amp;markers=50.916780,5.347420&amp;sensor=false">

这会返回 Google 的错误,指出:

The Google Maps API server rejected your request. Invalid request. Missing the 'size' parameter.

为什么 Google Static Maps API 不支持查询字符串中包含 & 的有效网址?

最佳答案

您正确转义了 & 字符。

请注意,您无法将带有转义与号的 URI 直接输入到浏览器的地址栏中。它仅在 HTML 中使用时才有效(即在 hrefsrc 属性中)。

URL in question works完美地作为链接(也作为图像)。


请注意,您可能don’t have to escape这些&符号(因为它们看起来很明确);但为了安全起见,只需避开它们即可。

关于url - 为什么 Google 不支持查询字符串中包含 & 的有效网址?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19678879/

相关文章:

java - URL 无法打开文件 :\C filepath in Java

java - Saml 2.0 请求编码

Java URL 参数用空格替换 %20

google-maps - 如何处理Google静态 map 中的 "Imagery not available"错误?

javascript - 如何在Jquery Mobile中恢复页面URL?

swift 3 : Fast file path separation

google-maps-markers - 在静态谷歌地图 URL 中使用 "@2x"

polygons - 如何在 Google Static Maps API 中创建内部有孔的多边形?

php - 在 PHP 中将复杂的 URL 作为参数传递

ios - 二进制图像 POST - iOS