Corrigir o erro HTTP/1.1 403 Forbiddden na utilização do componente Indy IdHTTP com Delphi
Em alguns casos, em requisições com o componente TIDHttp,
ocorre o erro HTTP/1.1 403 Forbiddden.
Como resolver?
Simples, apenas setar alguns parâmetros.
Veja
1
2
3
4
| IdHTTP1.Request.Accept := 'text/html, */*';
IdHTTP1.Request.UserAgent := 'Mozilla/3.0 (compatible; IndyLibrary)';
IdHTTP1.Request.ContentType := 'application/x-www-form-urlencoded';
IdHTTP1.HandleRedirects := True; |
IdHTTP1.Request.Accept := 'text/html, */*';
IdHTTP1.Request.UserAgent := 'Mozilla/3.0 (compatible; IndyLibrary)';
IdHTTP1.Request.ContentType := 'application/x-www-form-urlencoded';
IdHTTP1.HandleRedirects := True;
Exemplo de uso:
Crie um novo formulário, adicione um botão, um TMemo e um
TIDHttp.
No OnClick do botão, deixe conforme o exemplo abaixo
1
2
3
4
5
6
7
8
9
10
11
| procedure TForm1.Button1Click(Sender: TObject);
var
HTML : string;
begin
IdHTTP1.Request.Accept := 'text/html, */*';
IdHTTP1.Request.UserAgent := 'Mozilla/3.0 (compatible; IndyLibrary)';
IdHTTP1.Request.ContentType := 'application/x-www-form-urlencoded';
IdHTTP1.HandleRedirects := True;
HTML := IdHTTP1.Get('http://showdelphi.com.br');
Memo1.Text := (HTML);
end; |
procedure TForm1.Button1Click(Sender: TObject);
var
HTML : string;
begin
IdHTTP1.Request.Accept := 'text/html, */*';
IdHTTP1.Request.UserAgent := 'Mozilla/3.0 (compatible; IndyLibrary)';
IdHTTP1.Request.ContentType := 'application/x-www-form-urlencoded';
IdHTTP1.HandleRedirects := True;
HTML := IdHTTP1.Get('http://showdelphi.com.br');
Memo1.Text := (HTML);
end;
Fonte de base: http://portalclique.com/programacao/corrigindo-o-erro-http1-1-403-forbiddden-com-delphi/
-
Giovani Da Cruz
-
10.810 views
- 0 comentários
- 8 de novembro de 2016
Está gostando do conteúdo? Considere pagar um cafezinho para nossa equipe!
Posts Relacionados - Continue Aprendendo