Android Question HttpUtils2 / XMLRPC

MarcoRome

Expert
Licensed User
Longtime User
Hi all. I try traslate this code in pyton:

B4X:
DEV_KEY = 'RwYtcwQz85DUpn6FPQCU7ImB2MBM8Dfl'

s1 = Server('http://muovi.roma.it/ws/xml/autenticazione/1')
s2 = Server('http://muovi.roma.it/ws/xml/paline/7')

token = s1.autenticazione.Accedi(DEV_KEY, '')

res = s2.paline.Previsioni(token, '70101', 'it')
pprint(res)

i have in main this code:

B4X:
Dim bus As busromaclass
bus.Initialize("RwYtcwQz85DUpn6FPQCU7ImB2MBM8Dfl")

and in my class busromaclass i have this code:

B4X:
Public Sub Initialize(password As String)
     Dim job1 As HttpJob
    job1.Initialize("MyJob", Me)
    job1.Download("http://muovi.roma.it/ws/xml/autenticazione/1")
    job1.GetRequest.SetHeader("autenticazione.Accedi", Array As String(password, ""))
    job1.GetRequest.SetHeader("Content-Type", "application/json")
    job1.GetRequest.SetContentEncoding("text/plain")

End Sub

Private Sub JobDone(job As HttpJob)

    If job.Success Then
        Dim res As String
        res = job.GetString
        Log("Response from server: " & res)
    Else
        ToastMessageShow("Error: " & job.ErrorMessage, True)
    End If
    job.Release
End Sub

No errors, Sub Initialize work without problem but finish there.
He does not come in JobDone.
( In attachment source )
Any idea ?
Thank you all
Marco
 

Attachments

  • BusRoma.zip
    8.1 KB · Views: 174
Last edited:

ArminKH

Well-Known Member
Hi all. I try traslate this code in pyton:

B4X:
DEV_KEY = 'RwYtcwQz85DUpn6FPQCU7ImB2MBM8Dfl'

s1 = Server('http://muovi.roma.it/ws/xml/autenticazione/1')
s2 = Server('http://muovi.roma.it/ws/xml/paline/7')

token = s1.autenticazione.Accedi(DEV_KEY, '')

res = s2.paline.Previsioni(token, '70101', 'it')
pprint(res)

i have in main this code:

B4X:
Dim bus As busromaclass
bus.Initialize("RwYtcwQz85DUpn6FPQCU7ImB2MBM8Dfl")

and in my class busromaclass i have this code:

B4X:
Public Sub Initialize(password As String)
     Dim job1 As HttpJob
    job1.Initialize("MyJob", Me)
    job1.Download("http://muovi.roma.it/ws/xml/autenticazione/1")
    job1.GetRequest.SetHeader("autenticazione.Accedi", Array As String(password, ""))
    job1.GetRequest.SetHeader("Content-Type", "application/json")
    job1.GetRequest.SetContentEncoding("text/plain")

End Sub

Private Sub JobDone(job As HttpJob)

    If job.Success Then
        Dim res As String
        res = job.GetString
        Log("Response from server: " & res)
    Else
        ToastMessageShow("Error: " & job.ErrorMessage, True)
    End If
    job.Release
End Sub

No errors, Sub Initialize work without problem but finish there.
He does not come in JobDone.
( In attachment source )
Any idea ?
Thank you all
Marco
jobdone raised for me without any error and all things are perfect
what u mean?
upload_2015-7-19_0-10-14.png
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
Thank you Erel for your response.
Yes i see already, but i dont see another way.
I will like understand as this code can traslate in B4A.
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
You you have any developer-documentation about their protocol? In english?
I dont know python
Hi dear DonMandred dont exist in english. But i traslate for you.


B4X:
Python
The following example shows how to authenticate with the API Getting around Rome (you must have a key developer), and invoke a method. You can simply paste the code below into a Python shell, after the necessary amendments to variable DEV_KEY.
try:
  # 2 Python import
  from xmlrpclib import Server
except ImportError:
  # 3 Python import
  from xmlrpc.client import Server

from pprint import pprint

DEV_KEY = 'Insert your key'

s1 = Server ('http://muovi.roma.it/ws/xml/autenticazione/1')
s2 = Server ('http://muovi.roma.it/ws/xml/paline/7')

token = s1.autenticazione.Accedi (DEV_KEY, '')

res = s2.paline.Previsioni (token, '70101', 'en')
pprint (res)

Other languages
The use of the API in other languages is similar to the case of Python. You need to download a library XML-RPC for its language and to study the documentation.
Developers are invited to share code samples in different programming languages.

The Key is: RwYtcwQz85DUpn6FPQCU7ImB2MBM8Dfl

Now i'm already try with THIS LIBRARY and work only if you have 1 parameter:

B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim XMLRPC1 As XMLRPC
    Dim XMLRPC2 As XMLRPC

End Sub

Sub Activity_Create(FirstTime As Boolean)
    If FirstTime Then
        XMLRPC1.Initialize("XMLRPC1")
        XMLRPC2.Initialize("XMLRPC2")
    End If
'Get Token
XMLRPC1.initXMLRPCClient("http://muovi.roma.it/ws/xml/autenticazione/1")
Dim vedi As String = XMLRPC1.objectCall2("autenticazione.Accedi","QCOT7MBQwaC8dQI3BcVEC58kTCeriOOi","")
Log(vedi) '<---- Return Token

'Get Palina Value
XMLRPC2.initXMLRPCClient("http://muovi.roma.it/ws/xml/paline/7")
Dim previsioni As Object  = XMLRPC2.objectCall3("paline.Previsioni",vedi,70101,"")
Log(previsioni) ' i wait that here return value

The first result is ok (XMLRPC1 ), come back token without problem.
The second result (XMLRPC2 ) dont work
in Log Previsioni i have this result:
{id_richiesta=11d4dc1182cc01abde46f3a23c362914, risposta={primi_per_palina=[Ljava.lang.Object;@41b52ac0, arrivi=[Ljava.lang.Object;@41b50fd0, nome=LGT GIANICOLENSE/REGINA COELI, collocazione=LTV GIANICOLENSE, 70 M. PRIMA SBOCCO PONTE MAZZINI}}

in another cases Erel response that is possible connect with web service with Http Library
example HERE

But i dont undestand ....
 
Upvote 0
Top