Test d'une URL avec redirection (curl / wget)
Bonjour,
Un webservice renvoie des documents. Il y a parfois des erreurs (400 et 404) et nous voudrions mettre en place un script vérifiant ces URL. Le problème est qu'il y a une redirection et que le webservice interrogé par curl retourne toujours 200.
Mon script testant le webservice :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| #!/bin/bash
# Conversion fichier Windows -> Unix vers un fichier temporaire
sed $'s/\r$//' $1 > sae_temp.csv
# Suppression du fichier de resultat s'il existe
if [ -e sae_resultat_${1} ]
then rm sae_resultat_${1}
fi
# Traitement du fichier
# Format du fichier resultat : libelle de l'application;URL;code HTTP de retour (200 = OK)
while IFS=';' read dateSolicitation libelleAppli nirod numenvoi url
do
urlstatus=$(curl -o /dev/null --silent --head --write-out '%{http_code}' "$url" )
echo "$libelleAppli;$url;$urlstatus" >> sae_resultat_${1}
# urlstatus=$(curl -o /dev/null --silent --head --write-out '%{http_code}' "$url" )
# echo "$libelleAppli;$url;$urlstatus" >> sae_resultat_${1}
done < sae_temp.csv
# Suppression du fichier temporaire
rm sae_temp.csv |
Le retour du webservice dont nous n'avons pas le code :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| <HTML><HEAD>
<TITLE></TITLE>
<META HTTP-EQUIV="content-type" content="text/html; charset=ISO8859-1">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<META HTTP-EQUIV="expires" CONTENT="0">
<SCRIPT LANGUAGE="Javascript">
var etatComposant = null;
alea=100000*(Math.random());
var urlJS = "http://127.0.0.1:123/testcomposant?" + alea;
function urlTestComposant()
{
document.write("<SCRIPT LANGUAGE='JavaScript' SRC='" + urlJS + "'><\/SCRIPT>");
}
urlTestComposant();
</SCRIPT>
</HEAD><BODY>
<FORM NAME="formSrvSec" ACTION="http://127.0.0.1:123/secjava" METHOD="GET">
<INPUT type="hidden" name="SERVEUR" value="http://mon.serveur.com:1234/MetierGet/?version=">
<INPUT type="hidden" name="ALEA" value="13C818C37C426FF7">
<INPUT type="hidden" name="SYSTEM" value="SY_XXX">
<INPUT type="hidden" name="ATTRIBUTS" value="XYZ">
</FORM>
<SCRIPT LANGUAGE="Javascript">
if (etatComposant != null)
{
val = document.formSrvSec.SERVEUR.value + etatComposant
document.formSrvSec.SERVEUR.value = val;
document.formSrvSec.submit();
}
else
{
url = document.formSrvSec.elements["SERVEUR"].value + "null&Jeton=SRVSEC_INDISPONIBLE";
document.location.href = url;
}
</SCRIPT>
</BODY></HTML> |