我正在尝试使用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;
Run Code Online (Sandbox Code Playgroud)
但是我一直得到HTTP/1.0 403 Forbidden的响应.我认为这意味着我没有权限提出此请求但是如果我将网址复制到我的网络浏览器IE 8中,它可以正常工作.是否有我需要的标题信息或其他内容?
使用以下代码,我得到异常类EIdHTTPProtocolException,消息'HTTP/1.1 403 Forbidden'.处理svchostip.exe(11172)
function GetInternetIP:string;
var
IdHTTPMainUrl : TIdHTTP;
begin
try
IdHTTPMainUrl := TIdHTTP.Create(nil);
IdHTTPMainUrl.Request.Host := 'http://www.whatismyip.com/automation/n09230945.asp';
Result := idHTTPMainUrl.Get('http://automation.whatismyip.com/n09230945.asp');
except
IdHTTPMainUrl.Free;
end;
end;
Run Code Online (Sandbox Code Playgroud)