IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

 Delphi Discussion :

Poster les données par TWebBorwser


Sujet :

Delphi

  1. #1
    Membre du Club
    Homme Profil pro
    Tutulaire d'un Master Academique en Réseaux et Systèmes repartis
    Inscrit en
    Juin 2011
    Messages
    227
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Algérie

    Informations professionnelles :
    Activité : Tutulaire d'un Master Academique en Réseaux et Systèmes repartis
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2011
    Messages : 227
    Points : 51
    Points
    51
    Par défaut Poster les données par TWebBorwser
    Salut tous le monde, je cherche s'il y a un moyen d'obtenir les headers et poster avec les données en utilisant TWebBrowser.

    J'ai trouvé ce code mais ça n'a pas marcher

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    var
      strData: string;
      PostData: OleVariant;
      Headers: OleVariant;
      i: Integer;
    begin
      {1. you must create a string with parameter names and values
      Result string must be in the next format:
      Param1=Value1&Param2=Value2&Param3=Value3...}
      strData := 'Param1Name=' + HTTPEncode(Param1Value) + '&' +
        'Param2Name=' + HttpEncode(Param2Value) + ...;
     
      {2. you must convert a string into variant array of bytes and
       every character from string is a value in array}
      PostData := VarArrayCreate([0, Length(strData) - 1], varByte);
     
      { copy the ordinal value of the character into the PostData array}
      for i := 1 to Length(strData) do
        PostData[i-1] := Ord(strData[i]);
     
      {3. prepare headers which will be sent to remote web-server}
      Headers := 'Content-Type: application/x-www-form-urlencoded' + #10#13;
     
      {4. you must navigate to the URL with your script and send as parameters
      your array with POST-data and headers}
     
      yourWebBrowserComponent.Navigate('http://www.yourdomain.com/your_post_script.asp', EmptyParam, EmptyParam, PostData, Headers);
    end;
    Y a t'il des pistes pour commencer ?

    Merci à tous.

  2. #2
    Membre régulier
    Homme Profil pro
    pas grand chose
    Inscrit en
    Septembre 2018
    Messages
    131
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Loir et Cher (Centre)

    Informations professionnelles :
    Activité : pas grand chose
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Septembre 2018
    Messages : 131
    Points : 73
    Points
    73
    Par défaut
    Bon je sais pas si la question est toujours d actualité mais j ai trouvé ça:

    pour récupérer les entêtes :
    http://www.delphigroups.info/2/10/208485.html en bas de page.

    et pour poster https://www.developpez.net/forums/d1...e-post-idhttp/

  3. #3
    Membre averti
    Profil pro
    Inscrit en
    Janvier 2009
    Messages
    322
    Détails du profil
    Informations personnelles :
    Localisation : Canada

    Informations forums :
    Inscription : Janvier 2009
    Messages : 322
    Points : 310
    Points
    310
    Par défaut
    Je travaille avec ça...

    A+


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    function RemplisFormulaire2(navigateur:twebbrowser;informations:string):boolean;
    //informations contient les chaines séparé par #13
    //Chaque mot est séparé par des espaces
     
    var
      i,j,k: Integer;
      FormItem: Variant;
     
      l,m:tstringlist;
     
    begin
        Result := informations='';
        if result then exit;
        if (navigateur.OleObject.Document.all.tags('FORM').Length = 0) and
           (navigateur.OleObject.Document.all.tags('form').Length = 0)
                                                                     then Exit;   //no form on document
        l:=tstringlist.create;l.text:=informations;
        m:=tstringlist.create;m.delimiter:=',';
        //count forms on document
        for I := 0 to navigateur.OleObject.Document.forms.Length - 1 do begin
            FormItem := navigateur.OleObject.Document.forms.Item(I);
            for j := 0 to l.count-1 do begin
                m.delimitedtext:=l[j];
                for k:=0 to FormItem.Length - 1 do if m.count>1 then try
                    if (FormItem.Item(k).id = m[0]) or (FormItem.Item(k).name = m[0]) then begin
                        FormItem.Item(k).Value :=m[1];
                        result:=true;//si on rempli au moin une case c'est bon
                    end;
                except
                    l.free;
                    m.free;
                    exit;
                end;
            end;
        end;
        l.free;
        m.free;
    end;
    function RemplisFormulaire(navigateur:twebbrowser;informations:string):boolean;
    //informations contient les chaines séparé par #13
    //Chaque mot est séparé par des espaces
     
    var
      i,j,k,ii: Integer;
      FormItem: Variant;
     
      l,m:tstringlist;
     
    begin
        Result := informations='';
        if result then exit;
        if (navigateur.OleObject.Document.all.tags('FORM').Length = 0) and
           (navigateur.OleObject.Document.all.tags('form').Length = 0)
                                                                     then Exit;   //no form on document
        l:=tstringlist.create;l.text:=informations;
        m:=tstringlist.create;m.delimiter:=',';
        //count forms on document
        for I := 0 to navigateur.OleObject.Document.forms.Length - 1 do begin
            FormItem := navigateur.OleObject.Document.forms.Item(I);
            for j := 0 to l.count-1 do begin //tout les champs a remplir
                m.delimitedtext:=l[j];
                for k:=0 to FormItem.Length - 1 do if m.count>1 then try
                    for ii:=0 to m.count-2 do if (FormItem.Item(k).id = m[ii]) or (FormItem.Item(k).name = m[i]) then begin
                        FormItem.Item(k).Value :=m[m.count-1];
                        result:=true;//si on rempli au moin une case c'est bon
                        break;//termine la boucle ii car succèes
                    end;
                except
                    l.free;
                    m.free;
                    exit;
                end;
            end;
        end;
        l.free;
        m.free;
    end;
     
     
     
     
     
    function CliqueFormulaireHTML(navigateur:twebbrowser;informations:string):boolean;
    var
      doc         : ihtmldocument2;
      Collection  : IHTMLElementCollection;
      IDP         : IDispatch;
      i           : integer;
      InputButton : HTMLInputButtonElement;
      l:tstringlist;
     
    begin
        result:=false;
        l:=tstringlist.create;l.DelimitedText:=informations;
        doc := (navigateur.document as ihtmldocument2);
        if Assigned(doc) then begin
            IDP := Doc.all.tags('input');
            if Assigned(IDP) then begin
                IDP.QueryInterface(IHTMLElementCollection, Collection);
                if Assigned(Collection) then begin
                   for i := 0 to Collection.Get_length-1 do begin
                      IDP:= Collection.item(i, 0);
                      IDP.QueryInterface(HTMLInputButtonElement{HTMLInputImage{}, InputButton);
                      if (InputButton.Name = l[0]) or (InputButton.Id = l[0]) then begin
                          InputButton.Click;
                          result:=true;
                          break;
                      end;
                   end;
                end;
            end;
        end;
        l.free;
     
    end;
     
    function CliqueLien(navigateur:twebbrowser;informations:string):boolean;
    var
        i: integer;
        ovLinks: OleVariant;
        l:tstringlist;
    begin
        result:=false;
        l:=tstringlist.create;l.DelimitedText:=informations;
        ovLinks := navigateur.OleObject.Document.all.tags('A');//extrait les liens
        if ovLinks.Length > 0 then begin
            for i := 0 to ovLinks.Length-1 do begin
                if Pos(l[0], ovLinks.Item(i).href) > 0 then begin
                    ovLinks.Item(i).click;
                    Break;
                end;
            end;
         end;
        l.free;
    end;
     
    function CliqueFormulaireJavaScript(navigateur:twebbrowser;informations:string):boolean;
    var l:tstringlist;
        //s:string;
        iWindow : IHTMLWindow2;
        iDoc : IHTMLDocument2;
    begin
        result:=false;
        iDoc := navigateur.Document as IHTMLDocument2;
        if not Assigned(iDoc) then Exit;
        l:=tstringlist.create;
        l.Text:=informations;
        try
            iWindow := iDoc.parentWindow;
            iWindow.execScript('javascript:document.getElementById(' + QuotedStr(l[0]) + ').click();', 'javascript');
            result:=true;
        except
        end;
        l.free;
    end;
     
    function RemplisEtCliqueFormulaire(navigateur:twebbrowser;informations:string):boolean;
    var l:tstringlist;s:string;
    begin
        l:=tstringlist.create;
        l.Text:=informations;
        result:=false;
        try
           s:=l[l.count-1];
           l.Delete(l.count-1);
     
           if RemplisFormulaire(navigateur,l.Text) then
              if cliquelien(navigateur,s) then result:=true else
              if CliqueFormulairehtml(navigateur,s) then result:=true else
              if CliqueFormulaireJavaScript(navigateur,s) then result:=true;
        except
           result:=false;
        end;
        l.free;
    end;
    En adaptant ça

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    function Recenseliens(navigateur:twebbrowser;var liens:string):boolean;overload;
    var
        i:integer;
    begin
        result:=0<navigateur.OleObject.Document.all.tags('A').length;
        if not result then exit;
     
        liens:=navigateur.OleObject.Document.all.tags('A').item(0).href;
     
        for i := 1 to navigateur.OleObject.Document.all.tags('A').length-1 do
            liens:=liens+#13#10+
                navigateur.OleObject.Document.all.tags('A').item(i).href;
     
    end;

Discussions similaires

  1. comment afficher les données par mois à partir d'un champs date ?
    Par M.a.n.u. dans le forum Requêtes et SQL.
    Réponses: 1
    Dernier message: 18/05/2008, 09h36
  2. Filtrer les données par DateTimePicker
    Par matrixdine dans le forum Windows Forms
    Réponses: 3
    Dernier message: 15/04/2008, 23h05
  3. Trier les données par date au format jour mois année...
    Par ouskel'n'or dans le forum Macros et VBA Excel
    Réponses: 2
    Dernier message: 30/08/2007, 11h41
  4. Regrouper les données par rapport à la date
    Par goldeagle dans le forum Access
    Réponses: 7
    Dernier message: 11/12/2006, 15h35
  5. [c#]Poster les données d'un formulaire http
    Par waxman1 dans le forum Windows Forms
    Réponses: 4
    Dernier message: 05/05/2006, 18h25

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo