Re: [twsocket] help on httpcli post
Hi RTT Thanks for sample. I play with it in few minutes. I read many off post even when are out of my programing knowledge, give me ideas how to do better my programs. Thanks again to all ICS folks. Xavi Al 12/10/2010 18:55, En/na RTT ha escrit: Here is a sample that work. Get the 'multipart/form-data' encode tstream class code from this unit: http://read.pudn.com/downloads116/sourcecode/internet/495621/Gz235_200671623235689/cn700_del549790557/IndyMultipartFormData/MsMultiPartFormData.pas__.htm Start a new Delphi application, and in the main form place: 1 THttpCli, 1 TButton, 1 TMemo 1 TOpenDialog function GetMimeType(fileName: string): string; var reg: tregistry; ext: string; begin result := 'application/unknown'; ext := lowercase(extractFileExt(filename)); reg := tregistry.Create; try reg.RootKey := HKEY_CLASSES_ROOT; if reg.OpenKey(ext, false) and reg.ValueExists('Content Type') then result := reg.ReadString('Content Type') finally reg.Free; end; end; procedure TForm1.UploadFile(url, Filename: string); var MultiPartFormDataStream: TMsMultiPartFormDataStream; fStream: TFileStream; begin fStream := TFileStream.Create(Filename, fmOpenRead); MultiPartFormDataStream := TMsMultiPartFormDataStream.create; MultiPartFormDataStream.AddFile('fileupload1', ExtractFileName(filename), GetMimeType(Filename), fstream); fStream.free; //there is a bug in the HFS code so we need to add a dummy field here MultiPartFormDataStream.AddFormField('fileupload2', ''); MultiPartFormDataStream.PrepareStreamForDispatch; MultiPartFormDataStream.Position := 0; Memo1.Lines.LoadFromStream(MultiPartFormDataStream); MultiPartFormDataStream.Position := 0; HttpCli1.ContentTypePost := 'multipart/form-data; boundary='+MultiPartFormDataStream.Boundary; HttpCli1.SendStream := MultiPartFormDataStream; HttpCli1.URL := url; HttpCli1.Post; HttpCli1.SendStream.free; end; procedure TForm1.Button1Click(Sender: TObject); begin if OpenDialog1.Execute then UploadFile('http://81.184.21.22:100/hfs/', OpenDialog1.FileName); end; I have just now upload a file with this code to your HFS server. -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be Se certifico que el correo entrante no contiene virus. Comprobada por AVG - www.avg.es Version: 9.0.862 / Base de datos de virus: 271.1.1/3192 - Fecha de la version: 10/12/10 08:34:00 -- Xavier Mor-Mur -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] help on httpcli post
Here is a sample that work. Get the 'multipart/form-data' encode tstream class code from this unit: http://read.pudn.com/downloads116/sourcecode/internet/495621/Gz235_200671623235689/cn700_del549790557/IndyMultipartFormData/MsMultiPartFormData.pas__.htm Start a new Delphi application, and in the main form place: 1 THttpCli, 1 TButton, 1 TMemo 1 TOpenDialog function GetMimeType(fileName: string): string; var reg: tregistry; ext: string; begin result := 'application/unknown'; ext := lowercase(extractFileExt(filename)); reg := tregistry.Create; try reg.RootKey := HKEY_CLASSES_ROOT; if reg.OpenKey(ext, false) and reg.ValueExists('Content Type') then result := reg.ReadString('Content Type') finally reg.Free; end; end; procedure TForm1.UploadFile(url, Filename: string); var MultiPartFormDataStream: TMsMultiPartFormDataStream; fStream: TFileStream; begin fStream := TFileStream.Create(Filename, fmOpenRead); MultiPartFormDataStream := TMsMultiPartFormDataStream.create; MultiPartFormDataStream.AddFile('fileupload1', ExtractFileName(filename), GetMimeType(Filename), fstream); fStream.free; //there is a bug in the HFS code so we need to add a dummy field here MultiPartFormDataStream.AddFormField('fileupload2', ''); MultiPartFormDataStream.PrepareStreamForDispatch; MultiPartFormDataStream.Position := 0; Memo1.Lines.LoadFromStream(MultiPartFormDataStream); MultiPartFormDataStream.Position := 0; HttpCli1.ContentTypePost := 'multipart/form-data; boundary='+MultiPartFormDataStream.Boundary; HttpCli1.SendStream := MultiPartFormDataStream; HttpCli1.URL := url; HttpCli1.Post; HttpCli1.SendStream.free; end; procedure TForm1.Button1Click(Sender: TObject); begin if OpenDialog1.Execute then UploadFile('http://81.184.21.22:100/hfs/', OpenDialog1.FileName); end; I have just now upload a file with this code to your HFS server. -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] help on httpcli post
Thanks Francois and Frans I will take look. May need is the most basic use of http get/post. Sporadically and need send files to servers for which I don't have any support/control. Some of them have ftp support, no problem with ICS, but troubles I come with http protocol. I'm a permanent beginner programmer. Many thanks for all Xavi Al 12/10/2010 14:44, En/na Francois PIETTE ha escrit: As I know HFS have a some kind of code but I don't know how to call it from client. Open on your navigator "http:// 81.184.21.22 :100/hfs/" and will see a very easy web page with list of files with two buttons "UPLOAD" and "LOGIN". Upload button allow select up to 10 files and then upload it using "UPLOAD FILES" button. HFS is one exe and one config file, don't need install and all work is done internally. The browser will interpret the JavaScript which is behind the form and post/get the files to the website. I suggest you use WireShark to see what URL your browser use to post the files. It is usually much easier to see what the browser do than trying to understand complex JavaScript which is probably written so that you cannot easily reverse engineer it. Any idea is welcome, in the mean time will try with options of HFS. I don't know your requirements, but why don't you write your own server program using ICS component ? You have everything you need there. -- francois.pie...@overbyte.be The author of the freeware multi-tier middleware MidWare The author of the freeware Internet Component Suite (ICS) http://www.overbyte.be -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be Se certifico que el correo entrante no contiene virus. Comprobada por AVG - www.avg.es Version: 9.0.862 / Base de datos de virus: 271.1.1/3192 - Fecha de la version: 10/12/10 08:34:00 -- Xavier Mor-Mur -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] help on httpcli post
As I know HFS have a some kind of code but I don't know how to call it from client. Open on your navigator "http:// 81.184.21.22 :100/hfs/" and will see a very easy web page with list of files with two buttons "UPLOAD" and "LOGIN". Upload button allow select up to 10 files and then upload it using "UPLOAD FILES" button. HFS is one exe and one config file, don't need install and all work is done internally. The browser will interpret the JavaScript which is behind the form and post/get the files to the website. I suggest you use WireShark to see what URL your browser use to post the files. It is usually much easier to see what the browser do than trying to understand complex JavaScript which is probably written so that you cannot easily reverse engineer it. Any idea is welcome, in the mean time will try with options of HFS. I don't know your requirements, but why don't you write your own server program using ICS component ? You have everything you need there. -- francois.pie...@overbyte.be The author of the freeware multi-tier middleware MidWare The author of the freeware Internet Component Suite (ICS) http://www.overbyte.be -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] help on httpcli post
Hi Xavier, Francois is trying to tell you that you need to read some more about the difference between post and get and the way those work in a form. Try the following Host: 81.184.21.22:100 url = POST /hfs/. data = fileupload1=C%3A%5CDocuments+and+Settings%5C%5CDesktop%5Ctest.txt&upbtn=Upload+files this will upload a file (test.txt) from the desktop of user XX to the server - Original Message - From: "Xavier Mor-Mur" To: "ICS support mailing" Sent: Tuesday, October 12, 2010 1:23 PM Subject: Re: [twsocket] help on httpcli post Hello Francois As I know HFS have a some kind of code but I don't know how to call it from client. Open on your navigator "http://81.184.21.22:100/hfs/"; and will see a very easy web page with list of files with two buttons "UPLOAD" and "LOGIN". Upload button allow select up to 10 files and then upload it using "UPLOAD FILES" button. HFS is one exe and one config file, don't need install and all work is done internally. I tried some demos using http post and only found one which works. Demo which works is "submitfile" from http://www.clevercomponents.com/products/inetsuite/demos/submitfile.asp I don't know it does but it works, but other http demos from same site using post don't work. Any idea is welcome, in the mean time will try with options of HFS. Regards Xavi Al 12/10/2010 09:48, En/na Francois PIETTE ha escrit: I try to include http get and post to my program and doing tests on OverbyteIcshttptst demo. I get function GET work but not with function POST. I configured at home free "HFS - HTTP File Server" from http://www.rejetto.com/hfs/ When running demo I set URL = http://81.184.21.22:100/hfs/c-obfuscado.txt Data = C:\Mis documentos\c-obfuscado.txt Button GET works and how text file in panel Button POST give sequence events bellow. POST Failed ! StatusCode = 404 ReasonPhrase = Request aborted on timeout Sure I missing to do something but I don't know what. You cannot do a post to a document link unless there is a script (or whatever code is required) at server side to handle the post. I suggest you first try posting using your favorite internet navigator to validate the webserver configuration, then you may start doing the same with the component. Usually, the webserver has an HTML form with some fields (including file field) and a submit button. behing the submit button, you have the URL used to "post" the form. This is the URL you have to use with the component. -- francois.pie...@overbyte.be The author of the freeware multi-tier middleware MidWare The author of the freeware Internet Component Suite (ICS) http://www.overbyte.be -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be Se certifico que el correo entrante no contiene virus. Comprobada por AVG - www.avg.es Version: 9.0.862 / Base de datos de virus: 271.1.1/3192 - Fecha de la version: 10/12/10 08:34:00 -- Xavier Mor-Mur -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] help on httpcli post
Hello Francois As I know HFS have a some kind of code but I don't know how to call it from client. Open on your navigator "http://81.184.21.22:100/hfs/"; and will see a very easy web page with list of files with two buttons "UPLOAD" and "LOGIN". Upload button allow select up to 10 files and then upload it using "UPLOAD FILES" button. HFS is one exe and one config file, don't need install and all work is done internally. I tried some demos using http post and only found one which works. Demo which works is "submitfile" from http://www.clevercomponents.com/products/inetsuite/demos/submitfile.asp I don't know it does but it works, but other http demos from same site using post don't work. Any idea is welcome, in the mean time will try with options of HFS. Regards Xavi Al 12/10/2010 09:48, En/na Francois PIETTE ha escrit: I try to include http get and post to my program and doing tests on OverbyteIcshttptst demo. I get function GET work but not with function POST. I configured at home free "HFS - HTTP File Server" from http://www.rejetto.com/hfs/ When running demo I set URL = http://81.184.21.22:100/hfs/c-obfuscado.txt Data = C:\Mis documentos\c-obfuscado.txt Button GET works and how text file in panel Button POST give sequence events bellow. POST Failed ! StatusCode = 404 ReasonPhrase = Request aborted on timeout Sure I missing to do something but I don't know what. You cannot do a post to a document link unless there is a script (or whatever code is required) at server side to handle the post. I suggest you first try posting using your favorite internet navigator to validate the webserver configuration, then you may start doing the same with the component. Usually, the webserver has an HTML form with some fields (including file field) and a submit button. behing the submit button, you have the URL used to "post" the form. This is the URL you have to use with the component. -- francois.pie...@overbyte.be The author of the freeware multi-tier middleware MidWare The author of the freeware Internet Component Suite (ICS) http://www.overbyte.be -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be Se certifico que el correo entrante no contiene virus. Comprobada por AVG - www.avg.es Version: 9.0.862 / Base de datos de virus: 271.1.1/3192 - Fecha de la version: 10/12/10 08:34:00 -- Xavier Mor-Mur -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] help on httpcli post
I try to include http get and post to my program and doing tests on OverbyteIcshttptst demo. I get function GET work but not with function POST. I configured at home free "HFS - HTTP File Server" from http://www.rejetto.com/hfs/ When running demo I set URL = http://81.184.21.22:100/hfs/c-obfuscado.txt Data = C:\Mis documentos\c-obfuscado.txt Button GET works and how text file in panel Button POST give sequence events bellow. POST Failed ! StatusCode = 404 ReasonPhrase = Request aborted on timeout Sure I missing to do something but I don't know what. You cannot do a post to a document link unless there is a script (or whatever code is required) at server side to handle the post. I suggest you first try posting using your favorite internet navigator to validate the webserver configuration, then you may start doing the same with the component. Usually, the webserver has an HTML form with some fields (including file field) and a submit button. behing the submit button, you have the URL used to "post" the form. This is the URL you have to use with the component. -- francois.pie...@overbyte.be The author of the freeware multi-tier middleware MidWare The author of the freeware Internet Component Suite (ICS) http://www.overbyte.be -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
[twsocket] help on httpcli post
Hello to all I try to include http get and post to my program and doing tests on OverbyteIcshttptst demo. I get function GET work but not with function POST. I configured at home free "HFS - HTTP File Server" from http://www.rejetto.com/hfs/ When running demo I set URL = http://81.184.21.22:100/hfs/c-obfuscado.txt Data = C:\Mis documentos\c-obfuscado.txt Button GET works and how text file in panel Button POST give sequence events bellow. Sure I missing to do something but I don't know what. You can play with this HFS server ( http://81.184.21.22:100 ) as I have to work with some ones like this. Thanks for any help Xavi Sequence of events for POST. [HttpCli1StateChange] [HttpCli1StateChange] [HttpCli1StateChange] [HttpCli1StateChange] [HttpCli1StateChange] [HttpCli1RequestHeaderBegin] [HttpCli1Command] POST /hfs/c-obfuscado.txt HTTP/1.0 [HttpCli1Command] Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */* [HttpCli1Command] Content-Type: application/x-www-form-urlencoded [HttpCli1Command] User-Agent: Mozilla/3.0 (compatible) [HttpCli1Command] Host: 192.168.2.2:100 [HttpCli1Command] Content-Length: 33 [HttpCli1RequestHeaderEnd] [HttpCli1Command] [HttpCli1SendBegin] [HttpCli1SendData] 33 [HttpCli1SendEnd] [HttpCli1StateChange] [HttpCli1StateChange] POST Failed ! StatusCode = 404 ReasonPhrase = Request aborted on timeout [RequestDone Error] 8 -- Xavier Mor-Mur -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be