Hi everyone, I want to send some files using ThttpCli and the Post Method. i've searched through the ML for code samples, etc...
Based upon what i've found, here's the code i've written (based upon ICS's httpPost example) : procedure THttpPostForm.PostButtonClick(Sender: TObject); var Data : String; crlf : String; lFs : TMemoryStream; lBoundary:string; begin crlf:=#13#10; lBoundary:='---------------------------01myboundary2'; HttpCli1.ContentTypePost:='multipart/form-data; boundary='+lBoundary; Data:=lBoundary+#13#10; Data:=Data+'Content-Disposition: form-data; name="FirstName"'#13#10#13#10; Data:=Data+Trim(FirstNameEdit.Text)+#13#10; Data:=Data+lBoundary+#13#10; Data:=Data+'Content-Disposition: form-data; name="LastName"'#13#10#13#10; Data:=Data+Trim(LastNameEdit.Text)+#13#10; Data:=Data+lBoundary+#13#10; Data:=Data+'Content-Disposition: form-data; name="Submit"'#13#10#13#10; Data:=Data+'Submit'+#13#10; {Data := 'FirstName=' + UrlEncode(Trim(FirstNameEdit.Text)) + '&' + 'LastName=' + UrlEncode(Trim(LastNameEdit.Text)) + '&' + 'Submit=Submit';} HttpCli1.SendStream := TMemoryStream.Create; HttpCli1.SendStream.Write(Data[1], Length(Data)); if ffileName<>'' then Begin lFs:=TMemoryStream.Create; lFs.LoadFromFile(fFileName); Data:=lBoundary+#13#10; Data:=Data+'Content-Disposition: form-data; name="monfichier"; filename="'+fFileName+'"'+crlf; Data:=Data+'Content-type: application/zip'+crlf+crlf; HttpCli1.SendStream.Write(Data[1], Length(Data)); lFs.SaveToStream(HttpCli1.SendStream); HttpCli1.SendStream.Write(crlf[1], Length(crlf)); End; Data:=lBoundary+'--'+crlf; HttpCli1.SendStream.Write(Data[1], length(data)); HttpCli1.SendStream.Seek(0, 0); HttpCli1.RcvdStream := TMemoryStream.Create; HttpCli1.URL := Trim(ActionURLEdit.Text); HttpCli1.PostAsync; end; using the WebServ application, here's what the c:\data.bin file says : ========DATA======== Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */* Content-Type: multipart/form-data; boundary=---------------------------01myboundary2 User-Agent: Mozilla/4.0 (compatible; ICS) Host: localhost:8080 Content-Length: 349 ---------------------------01myboundary2 Content-Disposition: form-data; name="FirstName" Guillaume ---------------------------01myboundary2 Content-Disposition: form-data; name="LastName" MAISON ---------------------------01myboundary2 Content-Disposition: form-data; name="Submit" Submit ---------------------------01myboundary2-- ========DATA======== using the form mentionned in the webserv demo here's what firefox sends (according to c:\data.bin): ========DATA======== Host: localhost:8080 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; fr-FR; rv:1.7.9) Gecko/20050713 Firefox/1.0.5 Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 Accept-Language: fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Connection: keep-alive Cache-Control: max-age=0 Content-Type: multipart/form-data; boundary=---------------------------2921238217421 Content-Length: 358 -----------------------------2921238217421 Content-Disposition: form-data; name="FirstName" Guillaume -----------------------------2921238217421 Content-Disposition: form-data; name="LastName" MAISON -----------------------------2921238217421 Content-Disposition: form-data; name="Submit" Button -----------------------------2921238217421-- ========DATA======== everything seems same, except for few more headers sent by firefox... well, seems same... but is not... when using the very same code (or form) against an apache server with PHP, i don't have the same result... with the sample code above, the apache/php server doesn't see any POST data with firefox it does... although i don't see any difference... anyone any idea ? or any sample code that works ;) ;) Guillaume MAISON ----- Guillaume MAISON - [EMAIL PROTECTED] 83, Cours Victor Hugo 47000 AGEN Tél : 05 53 87 91 48 - Fax : 05 53 68 73 50 e-mail : [EMAIL PROTECTED] - Web : http://nauteus.com -- To unsubscribe or change your settings for TWSocket mailing list please goto http://www.elists.org/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be