Question on htpputils

Toni

Member
Licensed User
Longtime User
Hello together,

at first let me say 'Thank you' to Erel for a great tool, (as far as I can rate as a newbie:sign0142:

I'd tried out to send a 'GET' query via Httputils to a server that should return a gpx file.
I used the code from your simple httputils example, but I doomed to failure just at the beginning:BangHead: . What's wrong? The string works fine on the PC's Browser (with a requestbox for saving the file) as well as in the webview view in b4a.
It is a query to cloudmade from the original example (incl. example key), I'd only removed the part with the sqare brackets to keep this post short. --> Routing - Wiki

Here is my (your) code and the log file:

Code:
Sub Globals
Dim myquery As String
myquery = "http://routes.cloudmade.com/8ee2a50541944fb9bcedded5165f09d9/api/0.3/54.5409,-2.9637,54.5409,-2.9637/foot.gpx"
End Sub

Sub Activity_Create (FirstTime As Boolean)
HttpUtils.CallbackActivity = "Main" 'Current activity name.
HttpUtils.CallbackJobDoneSub = "JobDone"
HttpUtils.Download("Job1", myquery)
End Sub

Sub JobDone (Job As String)
Dim in As InputStream
If HttpUtils.IsSuccess(myquery) Then
in = HttpUtils.Getinputstream(myquery)
End If
End Sub

Log:
** Activity (main) Create, isFirst = true **
Starting Job: Job1
** Activity (main) Resume **
** Service (httputilsservice) Create **
** Service (httputilsservice) Start **
Error. Url=http://routes.cloudmade.com/8ee2a50541944fb9bcedded5165f09d9/api/0.3/54.5409,-2.9637,54.5409,-2.9637/foot.gpx Message=Internal Server Error
Sorry, some unrecoverable error happened
** Service (httputilsservice) Destroy **

:sign0163: with an idea what I'm doing wrong?! Answers in german are very welcome as Ich bin Deutscher

Thanx a lot for :sign0085: Toni

P.S. I'd post this question 1st to forum's topics. How can I delete there?
 
I think you need to Encode your URL since it contains special charachters.
Look at: Basic4android - StringUtils

Decoded URL:
Code:
http://routes.cloudmade.com/8ee2a50541944fb9bcedded5165f09d9/api/0.3/54.5409,-2.9637,54.5409,-2.9637/foot.gpx

EncodedURL:
Code:
http://routes.cloudmade.com%2F8ee2a50541944fb9bcedded5165f09d9%2Fapi%2F0.3%2F54.5409%2C-2.9637%2C54.5409%2C-2.9637%2Ffoot.gpx
 
Upvote 0
Hi,
thanx for your fast support!

Unfortunality your encoded URL ends in:


** Activity (main) Create, isFirst = true **
Starting Job: Job1
** Activity (main) Resume **
** Service (httputilsservice) Create **
** Service (httputilsservice) Start **
Error. Url=http://routes.cloudmade.com%2F8ee2a50541944fb9bcedded5165f09d9%2Fapi%2F0.3%2F54.5409%2C-2.9637%2C54.5409%2C-2.9637%2Ffoot.gpx Message=java.lang.IllegalArgumentException: Host name may not be null
** Service (httputilsservice) Destroy **

Yet another idea?
 
Upvote 0
Hi,
I thing your URL is incorrect
myquery = "http://routes.cloudmade.com/8ee2a50541944fb9bcedded5165f09d9/api/0.3/54.5409,-2.9637,54.5409,-2.9637/foot.gpx"
if you paste it into a browser it does not work.
I tried one of their examples in an app and it works,
Code:
myqueryURL = "http://routes.cloudmade.com/8ee2a50541944fb9bcedded5165f09d9/api/0.3/51.22545,4.40730,%5B51.22,4.41,51.2,4.41%5D,51.23,4.42/car.js?lang=en&units=miles"

      HttpUtils.Download("gettrack", myqueryURL)
The original url was
"http://routes.cloudmade.com/8ee2a50541944fb9bcedded5165f09d9/api/0.3/51.22545,4.40730,[51.22,4.41,51.2,4.41],51.23,4.42/car.js?lang=en&units=miles"
I had to change the '[' and ']' for '%5B' and '%5D' for it to work, all of the other characters worked
 
Upvote 0
Hi,
I thing your URL is incorrect
if you paste it into a browser it does not work.
I tried one of their examples in an app and it works,
Code:
myqueryURL = "http://routes.cloudmade.com/8ee2a50541944fb9bcedded5165f09d9/api/0.3/51.22545,4.40730,%5B51.22,4.41,51.2,4.41%5D,51.23,4.42/car.js?lang=en&units=miles"

      HttpUtils.Download("gettrack", myqueryURL)
The original url was
I had to change the '[' and ']' for '%5B' and '%5D' for it to work, all of the other characters worked

Thank you, it seems to work (means no comments in the logfile), even I don't know what I'm doing wrong. Because at my tryout I deleted the square brackets from the example file...I've searched my whole device, but I can't find the hoppfully returned gpx-file.

Thank you
 
Upvote 0
It is probably stored in File.DirInternal.

What is in your JobDone sub?
When you get the inputstream from HttpUtils you can write it out anywhere you want.
Code:
Dim in As InputStream
If HttpUtils.IsSuccess(myquery) Then
in = HttpUtils.Getinputstream(myquery)
Dim out as OutputStream
out =file.OpenOutput(file.DirRootExternal,"yourfile",false)
File.Copy2(in,out)
out.close
End If
 
Upvote 0
The error in your 'myquery ' url was you deleted the destination coordinates when you took out the [] so it could not return the file.
If you want to directly see the data in your code you can use
Code:
If HttpUtils.IsSuccess(myquery) Then
      Dim in As InputStream

      in = HttpUtils.Getinputstream(myquery)
            
      Dim Reader As TextReader
          Reader.Initialize(in)
      Dim inputText As String
      inputText = Reader.ReadAll
      Log(inputText)
End If
 
Upvote 0
Hi to The desolatesoul and lagore,

you helped me out of my desperation! :sign0098:
Sorry for that questions I could answer by myself (like the wrong URLstring) if I had worked not so sloopy! :sign0013:

Thank you and I give you my :sign0188:

greetings from Germany
 
Upvote 0
Back
Top