T Toni Member Licensed User Longtime User Feb 18, 2012 #1 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?
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?
thedesolatesoul Expert Licensed User Longtime User Feb 18, 2012 #2 I think you need to Encode your URL since it contains special charachters. Look at: Basic4android - StringUtils Decoded URL: Code: Copy http://routes.cloudmade.com/8ee2a50541944fb9bcedded5165f09d9/api/0.3/54.5409,-2.9637,54.5409,-2.9637/foot.gpx EncodedURL: Code: Copy http://routes.cloudmade.com%2F8ee2a50541944fb9bcedded5165f09d9%2Fapi%2F0.3%2F54.5409%2C-2.9637%2C54.5409%2C-2.9637%2Ffoot.gpx Upvote 0
I think you need to Encode your URL since it contains special charachters. Look at: Basic4android - StringUtils Decoded URL: Code: Copy http://routes.cloudmade.com/8ee2a50541944fb9bcedded5165f09d9/api/0.3/54.5409,-2.9637,54.5409,-2.9637/foot.gpx EncodedURL: Code: Copy http://routes.cloudmade.com%2F8ee2a50541944fb9bcedded5165f09d9%2Fapi%2F0.3%2F54.5409%2C-2.9637%2C54.5409%2C-2.9637%2Ffoot.gpx
T Toni Member Licensed User Longtime User Feb 18, 2012 #3 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, 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?
lagore Active Member Licensed User Longtime User Feb 18, 2012 #4 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" Click to expand... if you paste it into a browser it does not work. I tried one of their examples in an app and it works, Code: Copy 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" Click to expand... 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 myquery = "http://routes.cloudmade.com/8ee2a50541944fb9bcedded5165f09d9/api/0.3/54.5409,-2.9637,54.5409,-2.9637/foot.gpx" Click to expand... if you paste it into a browser it does not work. I tried one of their examples in an app and it works, Code: Copy 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" Click to expand... I had to change the '[' and ']' for '%5B' and '%5D' for it to work, all of the other characters worked
thedesolatesoul Expert Licensed User Longtime User Feb 18, 2012 #5 Your URL does not look correct to me. Do you have an example from the cloudmade website? Upvote 0
T Toni Member Licensed User Longtime User Feb 18, 2012 #6 lagore said: 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: Copy 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 Click to expand... 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
lagore said: 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: Copy 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 Click to expand... 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
T Toni Member Licensed User Longtime User Feb 18, 2012 #7 thedesolatesoul said: Your URL does not look correct to me. Do you have an example from the cloudmade website? Click to expand... Please view to the post from lagore, he encoded correct. But as i wrote, there had no gpx returned. Thank you Upvote 0
thedesolatesoul said: Your URL does not look correct to me. Do you have an example from the cloudmade website? Click to expand... Please view to the post from lagore, he encoded correct. But as i wrote, there had no gpx returned. Thank you
thedesolatesoul Expert Licensed User Longtime User Feb 18, 2012 #8 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: Copy 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
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: Copy 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
lagore Active Member Licensed User Longtime User Feb 18, 2012 #9 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: Copy 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
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: Copy 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
T Toni Member Licensed User Longtime User Feb 18, 2012 #10 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
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
thedesolatesoul Expert Licensed User Longtime User Feb 18, 2012 #11 We all have those bleary eyed coding nights where we can see nothing wrong with our code Upvote 0