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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
| //---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
// pour "ventiler" les éléments de la réponse
rep = new TStringList();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ButtonReqHTTPClick(TObject *Sender)
{
// envoi de la requête (URL)
NMHTTP1->Get("http://192.168.221.136/axis-cgi/operator/param.cgi?action=list&group=motion");
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NMHTTP1Connect(TObject *Sender)
{
ShowMessage("Connecté");
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NMHTTP1PacketSent(TObject *Sender)
{
ShowMessage("Packet envoyé");
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NMHTTP1InvalidHost(bool &Handled)
{
ShowMessage("Hébergeur invalide");
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NMHTTP1ConnectionFailed(TObject *Sender)
{
ShowMessage("Echec de connexion");
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NMHTTP1AuthenticationNeeded(TObject *Sender)
{
ShowMessage("Authentification nécéssaire");
AnsiString AnID, APass;
InputQuery("Authentification nécessaire", "Entrez votre ID utilisateur", AnID);
InputQuery("Authentification nécessaire", "Entrez votre mot de passe", APass);
NMHTTP1->HeaderInfo->UserId = AnID;
NMHTTP1->HeaderInfo->Password = APass;
ShowMessage("Informations d'authentification définies, recommencez la dernière commande");
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NMHTTP1Success(CmdType Cmd)
{
ShowMessage("Operation réussi");
nbrecu = NMHTTP1->BytesRecvd ;
rep->Text = NMHTTP1->Body;
// test d'extraction de la valeur du champ "root.Motion.M0.History" de la réponse
AnsiString U = rep->Values["root.Motion.M0.History"]; // U contient alors l'AnsiString (ex: "90")
int val = U.ToInt();
} |
Partager