Recent

Author Topic: Send Data to url  (Read 6945 times)

magleft

  • Full Member
  • ***
  • Posts: 108
Send Data to url
« on: September 19, 2014, 08:22:00 pm »
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
windows 10 64

ChrisF

  • Hero Member
  • *****
  • Posts: 542
Re: Send Data to url
« Reply #1 on: September 19, 2014, 09:36:57 pm »
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.1411154359.1.1.utmcsr=forum.lazarus.freepascal.org|utmccn=(referral)|utmcmd=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[1E]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]PID31[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[1E]
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]PID31[1F]mousedetails[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).
« Last Edit: September 19, 2014, 09:55:04 pm by ChrisF »

derek.john.evans

  • Guest
Re: Send Data to url
« Reply #2 on: September 28, 2014, 05:08:58 pm »
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.
« Last Edit: September 28, 2014, 05:11:51 pm by derek.john.evans »

magleft

  • Full Member
  • ***
  • Posts: 108
Re: Send Data to url
« Reply #3 on: September 28, 2014, 06:50:25 pm »
I'll try.
Thanks.
windows 10 64

chrnobel

  • Sr. Member
  • ****
  • Posts: 283
Re: Send Data to url
« Reply #4 on: October 01, 2014, 01:29:24 pm »
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);
« Last Edit: October 01, 2014, 01:32:09 pm by chrnobel »

Timewarp

  • Full Member
  • ***
  • Posts: 144
Re: Send Data to url
« Reply #5 on: October 01, 2014, 02:07:32 pm »
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

  • Full Member
  • ***
  • Posts: 108
Re: Send Data to url
« Reply #6 on: October 02, 2014, 02:00:06 pm »
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.
 
windows 10 64

 

TinyPortal © 2005-2018