Requêtes HTTP (tech)
De Wiki1000
(Différences entre les versions)
(→Propriétés) |
|||
| Ligne 90 : | Ligne 90 : | ||
|Charge un document XML avec la réponse de la requête. | |Charge un document XML avec la réponse de la requête. | ||
|} | |} | ||
| + | |||
| + | ===Exemples=== | ||
| + | '''Utilisation de GET''' | ||
| + | <source lang='delphi'> | ||
| + | //Procedure TestHttp; | ||
| + | var http:THttpClient; | ||
| + | begin | ||
| + | http := ThttpClient.Create(nil); | ||
| + | http.URL := 'http://www.google.fr'; | ||
| + | try | ||
| + | http.Execute; | ||
| + | ShowMessage(http.ResponseStr); | ||
| + | except | ||
| + | ShowMessage(http.ErrorText); | ||
| + | end; | ||
| + | end; | ||
| + | </source> | ||
| + | |||
| + | '''Utilisation sur un accès authentifié''' | ||
| + | <source lang='delphi'> | ||
| + | //Procedure TestHttp; | ||
| + | var http:THttpClient; | ||
| + | begin | ||
| + | http := ThttpClient.Create(nil); | ||
| + | http.URL := 'http://localhost/secure/test.html'; | ||
| + | http.AuthenUserName := 'sage'; | ||
| + | http.AuthenPassword := 'sage'; | ||
| + | try | ||
| + | http.Execute; | ||
| + | ShowMessage(http.ResponseStr); | ||
| + | except | ||
| + | ShowMessage(http.ErrorText); | ||
| + | end; | ||
| + | end; | ||
| + | </source> | ||
| + | |||
| + | '''Utilisation sur un accès authentifié, informations dans l'URL''' | ||
| + | <source lang='delphi'> | ||
| + | //Procedure TestHttp; | ||
| + | var http:THttpClient; | ||
| + | begin | ||
| + | http := ThttpClient.Create(nil); | ||
| + | http.URL := 'http://sage:sage@localhost/secure/test.html'; | ||
| + | try | ||
| + | http.Execute; | ||
| + | ShowMessage(http.ResponseStr); | ||
| + | except | ||
| + | ShowMessage(http.ErrorText); | ||
| + | end; | ||
| + | end; | ||
| + | </source> | ||
| + | |||
| + | '''Utilisation sur un port particulier''' | ||
| + | <source lang='delphi'> | ||
| + | //Procedure TestHttp; | ||
| + | var http:THttpClient; | ||
| + | begin | ||
| + | http := ThttpClient.Create(nil); | ||
| + | http.URL := 'http://localhost:8080/test.html'; | ||
| + | try | ||
| + | http.Execute; | ||
| + | ShowMessage(http.ResponseStr); | ||
| + | except | ||
| + | ShowMessage(http.ErrorText); | ||
| + | end; | ||
| + | end; | ||
| + | </source> | ||
| + | |||
| + | '''Chargement d'un document XML''' | ||
| + | <source lang='delphi'> | ||
| + | var http:THttpClient; doc:TxmlDocument; | ||
| + | begin | ||
| + | doc := TxmlDocument.Create(nil); | ||
| + | http := ThttpClient.Create(nil); | ||
| + | http.URL := 'http://www.playr.ie/ns0.wsdl'; | ||
| + | try | ||
| + | http.Execute; | ||
| + | http.LoadXMLDocument(doc); | ||
| + | ShowMessage(doc.SaveToString); | ||
| + | except | ||
| + | ShowMessage(http.ErrorText); | ||
| + | end; | ||
| + | end; | ||
| + | </source> | ||
{{Footer|Code métier}} | {{Footer|Code métier}} | ||
[[category:Objets techniques]] | [[category:Objets techniques]] | ||
[[category:Objets itérateurs]] | [[category:Objets itérateurs]] | ||
Version du 6 août 2009 à 10:53
Sommaire |
Introduction
Les requêtes HTTP sont des objets techniques permettant d'exécuter des requêtes HTTP.
Propriétés
| AuthenUserName | Nom d'utilisateur pour un accès authentifié |
| AuthenPassword | Mot de passe de l'utilisateur pour un accès authentifié |
| ProxyHost | Nom de serveur du proxy |
| ProxyPort | Numéro de port du proxy |
| ProxyUserName | Nom d'utilisateur du proxy |
| ProxyPassword | Mot de passe de l'utilisateur du proxy |
| PostDataStr | Données à poster |
| PostDataFile | Nom de fichier contenant les données à poster. |
| PostContentType | Type de contenu des données à poster |
| Method | Type de méthode http |
| Url | Url de la requête |
| SafeUrl | Url encodée de la requête |
| TimeOut | Délai d'attente de la réponse |
| ResponseFileName | Nom de fichier recevant la réponse (GET) |
| ResponseStr | Chaîne contenant la réponse (GET) |
| HandleRedirects | Accepte les redirections |
| RedirectMaximum | Nombre maximum de redirections |
| SSL | Accepte SSL |
| AcceptCookies | Accepte les cookies |
| RequestInfos | Informations de l'entête de requête. |
| ResponseInfos | Informations de l'entête de réponse. |
| ErrorCode | Code d'erreur. |
| ErrorText | Texte de l'erreur. |
| ErrorContent | Contenu de l'erreur. |
| ErrorInfos | Informations sur l'erreur. |
Opérations
| Execute | Exécute la requête |
| LoadXMLDocument | Charge un document XML avec la réponse de la requête. |
Exemples
Utilisation de GET
//Procedure TestHttp; var http:THttpClient; begin http := ThttpClient.Create(nil); http.URL := 'http://www.google.fr'; try http.Execute; ShowMessage(http.ResponseStr); except ShowMessage(http.ErrorText); end; end;
Utilisation sur un accès authentifié
//Procedure TestHttp; var http:THttpClient; begin http := ThttpClient.Create(nil); http.URL := 'http://localhost/secure/test.html'; http.AuthenUserName := 'sage'; http.AuthenPassword := 'sage'; try http.Execute; ShowMessage(http.ResponseStr); except ShowMessage(http.ErrorText); end; end;
Utilisation sur un accès authentifié, informations dans l'URL
//Procedure TestHttp; var http:THttpClient; begin http := ThttpClient.Create(nil); http.URL := 'http://sage:sage@localhost/secure/test.html'; try http.Execute; ShowMessage(http.ResponseStr); except ShowMessage(http.ErrorText); end; end;
Utilisation sur un port particulier
//Procedure TestHttp; var http:THttpClient; begin http := ThttpClient.Create(nil); http.URL := 'http://localhost:8080/test.html'; try http.Execute; ShowMessage(http.ResponseStr); except ShowMessage(http.ErrorText); end; end;
Chargement d'un document XML
var http:THttpClient; doc:TxmlDocument; begin doc := TxmlDocument.Create(nil); http := ThttpClient.Create(nil); http.URL := 'http://www.playr.ie/ns0.wsdl'; try http.Execute; http.LoadXMLDocument(doc); ShowMessage(doc.SaveToString); except ShowMessage(http.ErrorText); end; end;
— Code métier — Développement DSM —
| Whos here now: Members 0 Guests 0 Bots & Crawlers 1 |