Send Data to url lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- magleft · 2014-09-19 18:22 Hi. I was wondering if it is way to  to connect in  a url. This page is  http://e-services.minagric.gr/ I have username and password and i want to create a appliacation to do the connection and send some data. Can someone to help me? Thanks ---------------------------------------------------------------------- ChrisF · 2014-09-19 19:36 Unless there are special APIs for this site, you can always study and then send/process the data the way your browser does it. For instance, an attempt to connect to this site with user='MyName' and password='MyPassword' with Firefox. Firefox is posting these data: Code: [Select]http://e-services.minagric.gr/UIDL?windowName=1 POST /UIDL?windowName=1 HTTP/1.1 Host: e-services.minagric.gr User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:32.0) Gecko/20100101 Firefox/32.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3 Accept-Encoding: gzip, deflate Content-Type: text/plain;charset=utf-8 Referer: http://e-services.minagric.gr/ Content-Length: 187 Cookie: JSESSIONID=f5bd3f21c4052fc480fd603e9d2a; __utma=214103555.280544018.1411154359.1411154359.1411154359.1; __utmb=214103555.1.10.1411154359; __utmc=214103555; __utmz=214103555.1 411154359.1.1.utmcsr=forum.lazarus.freepascal.org|utmccn=(referral)|ut mcmd=referral|utmcct=/index.php/topic,25874.msg157916/topicseen.html Connection: keep-alive Pragma: no-cache Cache-Control: no-cache b1cd3dcf-7e5b-4aad-aa6f- 02c135acb2cf[1D]MyName[1F]PID29[1F]text[1F]s[1E]6[1F]PID29[1F]c[1F]i[1 E]MyPassword[1F]PID30[1F]text[1F]s[1E]10[1F]PID30[1F]c[1F]i[1E]true[1F ]PID31[1F]state[1F]b[1E]1,245,435,false,false,false,false,1,34,16[1F]P ID31[1F]mousedetails[1F]s HTTP/1.1 200 OK Server: GlassFish Server Open Source Edition 3.0.1 Content-Type: application/json;charset=UTF-8 Transfer-Encoding: chunked Content-Encoding: gzip Vary: Accept-Encoding Date: Fri, 19 Sep 2014 19:25:20 GMT ---------------------------------------------------------- The interesting part is the post data themselves, of course: b1cd3dcf-7e5b-4aad-aa6f- 02c135acb2cf[1D]MyName[1F]PID29[1F]text[1F]s[1E]6[1F]PID29[1F]c[1F]i[1 E] MyPassword[1F]PID30[1F]text[1F]s[1E]10[1F]PID30[1F]c[1F]i[1E]true[1F]P ID31[1F] state[1F]b[1E]1,245,435,false,false,false,false,1,34,16[1F]PID31[1F]mo usedetails[1F]s You'll probably have to also study the html/javascript source code of the connexion page, in order to understand which and how the data are processed. Another possible solution is to try an embedded browser solution (sorry, this one is not in my domain, and I can't give any advices for this solution). ---------------------------------------------------------------------- derek.john.evans · 2014-09-28 15:08 I have had success with hidden TWebBrowser automation, but web sites are getting more dynamic these days, making it harder to automate. In Lazarus, you will need to install the LazActiveX.lpk package, then import the type library from C:\WINDOWS\system32\ieframe.dll http://wiki.lazarus.freepascal.org/LazActiveX Then read up on the TWebBrowser/IWebBrowser2 interfaces: (There is heaps of information from the Delphi camp since Delphi has had a TWebBrowser control for over a decade) http://www.cryer.co.uk/brian/delphi/twebbrowser/twebbrowser_events.htm http://msdn.microsoft.com/en-us/library/aa752127%28v=vs.85%29.aspx http://delphidabbler.com/articles?article=18 Once you have the pages loading, you will have a OleVariant containing the IHTMLDocument interface. So, start reading JavaScript doc's, since everything you can access is the same. Links, Images, Forms, etc. Commands like getElementById and getElementsByName are what you will need. Once you have a HTML element, you can change its value, click buttons, etc. http://msdn.microsoft.com/en- us/library/system.windows.forms.htmldocument%28v=vs.110%29.aspx That said, most login's these days are hard to automate. I have succeeded with Hotmail and YouTube, but you need to write code to adjust for changes in the dynamic interfaces, plus, it can be tricky to know when a document is completely loaded, since a lot of javascript is used in both. But, its dooo-able. ---------------------------------------------------------------------- magleft · 2014-09-28 16:50 I'll try. Thanks. ---------------------------------------------------------------------- chrnobel · 2014-10-01 11:29 You could run cURL as a shell command, using data from your program like this curlstring:='curl -X POST -F username='+username+' -F password='+password+' '; curlstring:=curlstring+' -F "filesToUpload=@'+ directory+'/'+filename+'" '; curlstring:=curlstring+' http://e-services.minagric.gr/' fpSystem(curlstring); ---------------------------------------------------------------------- Timewarp · 2014-10-01 12:07 This demo should be useful, if use TWebbrowser http://forum.lazarus.freepascal.org/index.php/topic,19506.0.html No need to install LazActiveX.lpk or import ieframe.dll Webbrowser runs in IE7 compatibility mode and modern pages might not support old IE. Demo has solution for this too. ---------------------------------------------------------------------- magleft · 2014-10-02 12:00 chrnobel: The webpage have and run more visual script. Therefore I think your proposal is not appropriate. Thanks anyway. Timewarp: I wil idea l try with your suggestion but not diplaying login in items. Do you have any idea why? I will study with Twebbrowser and i tried to write the code.