HttpUtils2 problem download2 syntax

Smee

Well-Known Member
Licensed User
Longtime User
I am trying to get job1.Download2 to work but i dont understand how it works

This works ok

B4X:
job1.Download("http://website.com/scores.php?secret=PW&id=showUser&deviceID="&deviceID&"&type=1")

this obviously does not work

B4X:
job1.Download2("http://website.com/scores.php?secret=Test&id=showUser&deviceID="&deviceID&"&type=1", _
            Array As String("name", value, "score", value2))

With the first statement i get 2 fields returned ok but the second throws an error.

What is the correct syntax for download2?
and how could i parse the result for download?

Thanks for any replies
 
Last edited:

Smee

Well-Known Member
Licensed User
Longtime User
Thanks Erel,
I tried that but the fields value and value2 are empty

I changed value to value1
I dimmed them in process globals
Dim value1,value2 As String

then
B4X:
Sub JobDone (Job As HttpJob)
   Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
Dim st As String
   If Job.Success = True Then
      Select Job.JobName
         Case "Job1", "Job2"
            'print the result to the logs
            Log(value1)
            Log(value2)
            st=Job.GetString
            Log(Job.GetString)

Although i still get a result in st
 
Upvote 0

Smee

Well-Known Member
Licensed User
Longtime User
This is an abbreviated log

** Service (httputils2service) Create **
** Service (httputils2service) Start **
JobName = Job1, Success = true
1
Joe
123456

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
** Activity (main) Pause, UserClosed = false **


** Service (httputils2service) Destroy **
 
Upvote 0

Smee

Well-Known Member
Licensed User
Longtime User
yeah i dont get that with download. Although i do with another query later on. I will try to work that out later

with download i get this

Installing file.
PackageAdded: package:scores.test
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Service (httputils2service) Create **
** Service (httputils2service) Start **
JobName = Job1, Success = true
Joe
123456
 
Last edited:
Upvote 0

Smee

Well-Known Member
Licensed User
Longtime User
Ok i was mixing two separate lines

this works ok
job1.Download("http://website.com/scores.php?secret=Test&id=view&start=0&end=100&type="&difficulty)

This does not

job1.Download2("http://website.com/scores.php", _
Array As String("secret", "Test", "id", "view", "start" ,0 ,"end", 100 , "type", 1, "name", value1, "score", value2))

the log is this from download2

Installing file.
PackageAdded: package:scores.test
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Service (httputils2service) Create **
** Service (httputils2service) Start **
JobName = Job1, Success = true
Joe
123456
** Service (httputils2service) Destroy **
But the fields value 1 and value2 are empty

the log results are from
Log(value1)
Log(value2)
st=Job.GetString
Log(Job.GetString)

hope this makes more sense

:BangHead:
 
Upvote 0

Smee

Well-Known Member
Licensed User
Longtime User
value1 and value2 variables should be set before you call job1.Download2(...).

Yes it does seem simple enough but i am not getting the expected results.

When you say the Variables should be set before I call download 2 i assume that you mean dim? That is done in
B4X:
Sub Process_Globals
Dim job1, job2, job3 As HttpJob
  Dim value1,value2 As String
End Sub

They return empty but if i look at the variable st i can see the correct result

B4X:
Sub JobDone (Job As HttpJob)
Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
Dim st As String
   If Job.Success = True Then
      Select Job.JobName
         Case "Job1", "Job2"
            'print the result to the logs
            Log(value1)
            Log(value2)
            st=Job.GetString
            Log(st)
            Log("")
 
Upvote 0

Smee

Well-Known Member
Licensed User
Longtime User
Erel,

I have stepped through the debugger to no avail. I have read through 7 pages of a search result of download2 still no success.
In the http module the example given the values are listed as strings, i dont understand how a result code be passed back to these strings but i tried it anyway, Didn't work

B4X:
job.Download2("http://www.example.com", _
'   Array As String("key1", "value1", "key2", "value2"))

As i said i have declared the two values to hold the return in globals but they are empty when the routines are finished.
The variable st does hold the correct result when called

st=Job.GetString

But how do i parse that to variables?
:BangHead::BangHead:
 
Upvote 0

Smee

Well-Known Member
Licensed User
Longtime User
ok i get that.
I realise that so ignoring the fact that the 2 variables are returning empty, how do i parse this correctly

B4X:
Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
st=Job.GetString
Log(st)

This gives this output
JobName = Job1, Success = true
Joe
123456

In between "Joe" & "12345" are characters probably Chr(10) and (13) how could i strip them from the variable that is returned?
 
Upvote 0

Smee

Well-Known Member
Licensed User
Longtime User
Erel,

I'm afraid that Download2 is simpler than you think. It is just a small utility that helps you correctly build the request query. It is not related to the response.

It took a while but the penny has finally dropped. Sometimes one cannot see the forest for the trees :signOops:

I will open a new thread for my other question

Thanks for the patience
 
Upvote 0
Top