Installation
Un fichier install.exe est fourni. Pour installer le composant sur votre poste ou votre serveur :
install CSHttpClient.dll
Exemples d'utilisation
Les exemples fournis par Coaelys sont écrit pour JScript, en voici d'autres permettant d'utiliser le composant avec VbScript.
Les lignes que vous devrez modifier sont inscrites en rouge.
Utilisation de la méthode POST :
<%@ LANGUAGE=VbScript %>
<%
'---- Le composant CsHttpClient.dll
'---- Utilisation d'une méthode post
Dim coalHttp
set CoalHttp = Server.CreateObject("Coalesys.CSHttpClient.1")
' Url de postage
CoalHttp.RequestURL = "http://monserveur/page_attente_post.asp"
' Paramétrage des valeurs à poster
CoalHttp.RequestBody = "param1=" & Server.URLEncode("Paramètre 1") _
& "¶m2=" & Server.URLEncode("Paramètre 2")
' Construction de l'entête
CoalHttp.RequestHeaders = "User-Agent: " & Request.ServerVariables("HTTP_USER_AGENT") &Vbcrlf _
& "Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/msword, application/vnd.ms-excel, */*" & Vbcrlf _
& "Accept-Language: fr" & Vbcrlf _
& "Content-Length: " & len(CoalHttp.RequestBody) & Vbcrlf _
& "Content-Type: application/x-www-form-urlencoded" & Vbcrlf _
& "Cache-Control: no-cache" & Vbcrlf
' On définit la méthode de postage des données
CoalHttp.Execute("POST")
' On affiche la réponse de la page
Response.Write(CoalHttp.ResponseBody(0))
set CoalHttp=nothing
%>
Pour tester cet exemple, créer une page page_attente_post.asp par exemple :
<%
response.write(request.form("param1")&"<br>")
response.write(request.form("param2")&"<br>")
%>
Utilisation avec une méthode GET
<%
'---- Le composant CsHttpClient.dll
'---- Utilisation d'une méthode get
Dim coalHttp
set CoalHttp = Server.CreateObject("Coalesys.CSHttpClient.1")
' Url de connexion
CoalHttp.RequestURL = "http://www.asp-magazine.com"
' Exécution de la méthode GET
CoalHttp.execute("GET")
' On affiche la réponse
'--- On récupère le statut renvoyé par le serveur
Response.Write(CoalHttp.ResponseStatus & "<br><br>")
'--- On récupère ici l'entête
Response.Write(CoalHttp.ResponseHeaders & "<br><br>")
'--- On récupère le contenu du document
Response.Write(Server.HTMLEncode(CoalHttp.ResponseBody(0)))
set coalHttp=nothing
%>
Afficher une image distante
<%
'---- Le composant CsHttpClient.dll
'---- Afficher une image distante
Response.ContentType= "image/gif"
Dim coalHttp
set CoalHttp = Server.CreateObject("Coalesys.CSHttpClient.1")
' Url de connexion
CoalHttp.RequestURL = "http://www.asp-magazine.com/b_asp_mag.gif"
' Exécution de la méthode GET
CoalHttp.execute("GET")
' On affiche la réponse
Response.BinaryWrite(CoalHttp.ResponseBody(1))
set coalHttp=nothing
%>
Téléchargement
http://www.coalesys.com/products/httpclient/download/