Club Delphi  
    Paypal   FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Internet
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Colaboración Paypal con ClubDelphi

 
 
Herramientas Buscar en Tema Desplegado
  #5  
Antiguo 03-08-2006
Avatar de seoane
[seoane] seoane is offline
Miembro Premium
 
Registrado: feb 2004
Ubicación: A Coruña, España
Posts: 3.717
Poder: 26
seoane Va por buen camino
Una manera sencilla de hacerlo es como explica el compañero dec en el truco 346, utilizando los componentes Indy. Si no quieres complicarte mucho es la que te recomiendo.

Si quieres hacerlo mas difícil puedes usar Wininet, seria algo así:
Código Delphi [-]
uses Wininet;

function URLEncode(Str: string): string;
var
  i: integer;
begin
  Result:= '';
  for i:= 1 to Length(Str) do
    if Str[i] in ['A'..'Z','a'..'z','0'..'9','-','_','.'] then
      Result:= Result + Str[ i ]
    else
      Result:= Result + '%' + IntToHex(Ord(Str[ i ]),2);
end;

function HacerPost(Servidor, Cgi: string; Puerto: Word; Campos: TStringList): Boolean;
var
  hNet: HINTERNET;
  hCon: HINTERNET;
  hReq: HINTERNET;
  Context: DWORD;
  Mem: TMemoryStream;
  Str: string;
  i: integer;
  Buffer: array[0..10240] of Char;
  BytesRead: DWORD;
begin
  Context:= 0;
  Result := FALSE;
  Str:= '';
  hNet := InternetOpen('Agente', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
  if (hNet <> nil) then
  begin
    hCon:= InternetConnect(hNet,PChar(Servidor),Puerto,nil,nil,INTERNET_SERVICE_HTTP,0,Context);
    if (hCon <> nil) then
    begin
      hReq:= HttpOpenRequest(hCon,'POST',PChar(Cgi),nil,nil,nil,
        INTERNET_FLAG_RELOAD,Context);
      if (hReq <> nil) then
      begin
        for i:= 0 to Campos.Count - 1 do
        begin
          Str:= Str + '&' + urlencode(Campos.Names[i]) + '=' +
            urlencode(Campos.ValueFromIndex[i]);
        end;
        Delete(Str,1,1);
        Mem:= TMemoryStream.Create;
        try
          try
            if HttpSendRequest(hReq,nil,0,PChar(Str),Length(Str)) then
            begin
              while (InternetReadFile(hReq, @Buffer, sizeof(Buffer), BytesRead)) do
              begin
                if (BytesRead = 0) then
               begin
                  Result := TRUE;
                  break;
                end; 
                Mem.Write(Buffer,BytesRead);
              end;
              // La información resultante la tienes en el Stream, puedes guardarla
              // o utilizarla para lo que la necesites.
              Mem.SaveToFile('c:\1.html');
            end;
          except end;
        finally
          Mem.Free;
        end;
        InternetCloseHandle(hReq);
      end;
      InternetCloseHandle(hCon);
    end;
    InternetCloseHandle(hNet);
  end;
end;


var
  Campos: TStringList;
begin
  Campos:= TStringList.Create;
  try
    Campos.Values['Nombre1']:= 'Valor1';
    Campos.Values['Nombre2']:= '@#~¬='; // Un valor con caracteres especiales
    Campos.Values['Nombre3']:= 'Valor3';
    HacerPost('www.servidor.com','/cgi-bin/test.cgi',80,Campos);
  finally
    Campos.Free;
  end;
end;

Última edición por seoane fecha: 03-08-2006 a las 18:00:42.
Responder Con Cita
 



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Error Formulario forma modal serhasae Varios 5 03-04-2006 23:52:00
Codigo visual ASP.net para impresión de un formulario HombreSigma .NET 2 12-11-2005 05:10:27
pasar datos de un formulario vista a cualquier formulario @-Soft OOP 2 28-09-2004 21:56:01
existe una forma visual para crera tablas y consultas en interbase? viajero2015 Firebird e Interbase 4 21-02-2004 22:58:36
grabar datos en visual dbase botones67 Varios 1 19-07-2003 08:40:42


La franja horaria es GMT +2. Ahora son las 04:22:46.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi