Tuesday, 15 March 2011

delphi - Can you send a post to a website back to back with TIdHTTP? -


I have found a program that acts as an interface between a web server and a user who uploads the file to the user Allows the web server when the user clicks on "upload", then he takes information from the list view and sends it to the website, the first http.Post is for the actual file and the other is for meta-data that I Is collecting about it Not.

When I first comment on the post statement, it works fine and actually posts the data, but it seems that they do not take parameters for each other. It also works when I run scripts in a web browser with values ​​in Mercury.

EFI file is a record that has the file meta-data.

  IOHandler: = TIdSSLIOHandlerSocketOpenSSL. Creation; Http: = TIdHTTP.Create (zero); Http .IOHandler: IOHandler; Ultimate: = TStringList.Create; Datacaparam: = Tetum LiftformatDestream.Creat; Stream: = TStringStream.Create (''); DebugStream: = TStringStream.Create (''); Param.Add ('Serial =' + UFile.Serial); Param.Add ('file name =' + UFile.Name); Param.Add ('filepath =' + '\' + UFile.Serial + '\' + IntToStr (UFile.PatchID)); Param.Add ('patchid =' + IntToStr (UFile.PatchID)); Param.Add ('patchnotes =' + UFile.PatchNotes); Param.Add ('earliestversion =' + UFile.EarliestVersion); Param.Add ('latestversion =' + UFile.LatestVersion); Param.Add ('date =' + DateToStr (UFile.Date)); Param.Add ('execaftersend =' + BoolToStr (UFile.ExecAfterSend)); Dataparam Adfile ('file', 'Ufile.philip', 'app / octet-stream'); Try Http.Post ('http://example.com/postFile.php', Datapammaar, Stream); ShowMessage (Stream.DataString); Http.Post ('http://example.com/uploadFiles.php', Ultimate, debugestream); ShowMessage (DebugStream.DataString); For J: Debug = 0 Prade (para. Count): Strings: = debugging + '& amp; + Ultimate. Trings [ja]; ShowMessage (DebugStrings); Except e: EIdHTTPProtocolException ShowMessage begin ('Error code:' + IntToStr (E.ErrorCode)); End of end;    

Although this does not really solve the problem in posting two, this permission Lets you upload files with other files, which is why I was starting with two posts.

Use TIdMultiPartFormDataStream and add AddFile to your file, and add any other data with AddFormField.

Example:

  Dataparmar. Adfile ('File', Ufile.philpath, 'Applications / Octet-Stream'); Datapamamar AdFormield ('Serial', Ufile Serial); Dataparam EdFormield ('filename', 'Ufile .name');    

No comments:

Post a Comment