我正在尝试使用 TIdHTTP 组件从 Delphi 2006 中的maps.google.com 返回内容。
我的代码如下
procedure TForm1.GetGoogleMap();
var
t_GetRequest: String;
t_Source: TStringList;
t_Stream: TMemoryStream;
begin
t_Source := TStringList.Create;
try
t_Stream := TMemoryStream.Create;
try
t_GetRequest :=
'http://maps.google.com/maps/api/staticmap?' +
'center=Brooklyn+Bridge,New+York,NY' +
'&zoom=14' +
'&size=512x512' +
'&maptype=roadmap' +
'&markers=color:blue|label:S|40.702147,-74.015794' +
'&markers=color:green|label:G|40.711614,-74.012318' +
'&markers=color:red|color:red|label:C|40.718217,-73.998284' +
'&sensor=false';
IdHTTP1.Post(t_GetRequest, t_Source, t_Stream);
t_Stream.SaveToFile('google.html');
finally
t_Stream.Free;
end;
finally
t_Source.Free;
end;
end;
但是我不断收到响应 HTTP/1.0 403 Forbidden。我认为这意味着我没有权限发出此请求,但如果我将 url 复制到我的网络浏览器 IE 8 中,它就可以正常工作。是否有一些我需要的标题信息或其他信息?
最佳答案
您正在执行 POST
请求,但您的浏览器将执行 GET
请求;更改您的 delphi 代码以执行 GET
请求。
Google 可能被 UserAgent 屏蔽;尝试清除它,或更改它以匹配您的浏览器。
关于delphi - 如何使用 TIdHTTP 获取 Google 静态 map ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2696224/