Ver Mensaje Individual
  #2  
Antiguo 22-04-2004
tetemusic tetemusic is offline
Registrado
 
Registrado: abr 2004
Posts: 3
Reputación: 0
tetemusic Va por buen camino
Problema solucionado!

Con el objeto idHTTP he conseguido hacerlo. Aqui os pongo el código, por si os es útil:

Código:
const
CRLF = #13#10;
var
NomFitxer, path, codi, password: string;
Config: TInifile;
aStream: TMemoryStream;
Params: TMemoryStream;
S, linea: String;
F: TextFile;
begin
//enviamos fichero, sus datos y el user y password están en un .ini
path := ExtractFilePath(Application.ExeName);
Config := TIniFile.Create(path+'config.ini');
with Config do
begin
if ReadString('General','Path','Main') <> 'Main' then
path := ReadString('General','Path','Main');
if ReadString('General','Codi','Main') <> 'Main' then
codi := ReadString('General','Codi','Main');
if ReadString('General','Password','Main') <> 'Main' then
password := ReadString('General','Password','Main');
Free;
end;
OpenDialog1.InitialDir := path;
if OpenDialog1.Execute then
NomFitxer := OpenDialog1.FileName;
if NomFitxer <> '' then
begin
aStream := TMemoryStream.create;
Params := TMemoryStream.Create;
idHTTP1.Request.ContentType := 'multipart/form-data;boundary=-----------------------------7cf87224d2020a';
IdHTTP1.Request.Username := codi;
IdHTTP1.Request.Password := password;
try
S := '-----------------------------7cf87224d2020a' + CRLF + 'Content-Disposition: form-data; name="registro"; filename="'+RightStr(NomFitxer,14)+'"' + //registro es el nombre del campo del formulario html
CRLF + 'Content-Type: text/plain' + CRLF + CRLF;
Params.Write(S[1], Length(S));
//copiamos contenido del fichero al memory stream "params"
AssignFile(F,NomFitxer);
Append(F);
Reset(F);
while not EOF(F) do
begin
readln(F, linea);
if not EOF(F) then
linea := linea + CRLF;
Params.Write(linea[1],Length(linea));
end;
CloseFile(F);
S := CRLF +
'-----------------------------7cf87224d2020a';
Params.Write(S[1], Length(S));
try
idHTTP1.Post('https:// ... --aqui va a web--', Params,aStream);
except
on E: Exception do
showmessage('Error encountered during POST: ' + E.Message);
end;
aStream.SaveToFile(path+'\result.htm');
aStream.WriteBuffer(#0' ', 1);
showmessage(PChar(aStream.Memory));
except
end;
end;
end;

Última edición por tetemusic fecha: 22-04-2004 a las 16:03:28.
Responder Con Cita