Android Question How to use { and ]

thestar19

Member
Licensed User
Longtime User
Hey guys

So I solved my problem with downloading a image, But another problem has come up as a result.

I have spent several hours on this and still cant figure it out.

Basiclly, The adress where the pic is located contains { and } and for some reason I cant get the HTTPjob to except those. I have tried with Download2 but cant get that to work. See code below

I have tried using a map and some other stuff but it doesnt seem to be a problem with my code, but more the HTTPJob code.

B4X:
Sub Activity_Create(FirstTime As Boolean)
  Activity.LoadLayout("test_first")
try:
   image_view_1.Bitmap = LoadBitmap(File.DirRootExternal,"image.jpeg")
catch:
Log("There was a problem with the bitmap finding")
End try
job3.Download2("http://www.novasoftware.se/ImgGen/schedulegenerator.aspx?format=png&schoolid=52550/sv-se&type=1&id=aaaaaC9FBD960-702E-4549-8889-827B5A1EDB85aaaaaa&period=&week=46&mode=0&printer=0&colors=32&head=0&clock=0&foot=0&day=0&width=1883&height=887&maxwidth=1883&maxheight=887",Array As String("aaaaa","[","aaaaaa","]"))
End sub
Sub JobDone (Job As HttpJob)
  Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
  If Job.Success = True Then
  Select Job.JobName
  Case "Job1", "Job2"
  'print the result to the logs
  Log(Job.GetString)
  Case "Job3"
  'show the downloaded image
  Msgbox("Pic downloaded","")
       Dim outputstream1 As OutputStream
       Dim photo As Bitmap
       photo.Initialize3(Job.GetBitmap())
       'outputstream1.InitializeToBytesArray(1000)
       'photo.WriteToStream(outputstream1,10,"JPEG")
       Dim Out As OutputStream = File.OpenOutput(File.DirRootExternal, "image.jpeg", False)
      photo.WriteToStream(out, 90, "JPEG")
         out.Close
  End Select
  Else
  Log("Error: " & Job.ErrorMessage)
  ToastMessageShow("Error: " & Job.ErrorMessage, True)
  End If
  Job.Release
End Sub

The error I get looks like this:
B4X:
java.lang.IllegalArgumentException: Illegal character in query at index 99: http://www.novasoftware.se/ImgGen/schedulegenerator.aspx?format=png&schoolid=52550/sv-se&type=1&id={C9FBD960-702E-4549-8889-827B5A1EDB85}&period=&week=46&mode=0&printer=0&colors=32&head=0&clock=0&foot=0&day=0&width=1883&height=887&maxwidth=1883&maxheight=887

Can anybody help me?

Thank you
//
Thestar19
 

DouglasNYoung

Active Member
Licensed User
Longtime User
Thestar19,
'&' is a special charcter so you need to use a double && for it to work

ie
B4X:
job3.Download2("http://www.novasoftware.se/ImgGen/schedulegenerator.aspx?format=png&&schoolid=52550/sv-se&&type=1&&id=aaaaaC9FBD960-702E-4549-8889-827B5A1EDB85aaaaaa&&period=&&week=46&&mode=0&&printer=0&&colors=32&&head=0&&clock=0&&foot=0&&day=0&&width=1883&&height=887&&maxwidth=1883&&maxheight=887",Array As String("aaaaa","[","aaaaaa","]"))

Douglas
 
Upvote 0

moster67

Expert
Licensed User
Longtime User
I think you could also use the StringUtils library and the EncodeURL-method.

B4X:
Dim sut As StringUtils
Dim linkToEncode As String
linkToEncode = sut.EncodeUrl(linkToEncode, "UTF8")

Sometimes encoding the whole link does not work and in this case you can try to encode only the parameters you are passing on in your URL.
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
Well if i paste the url into my desktop browser it works - the browser doesn't complain that the url is invalid.
Not sure if that helps but it might indicate the problem is not with the actual url...

Martin.
 
Upvote 0

thestar19

Member
Licensed User
Longtime User
Tried all, The problem lays at the {, } part. Nothing worked

Worked for a couple of hours on modefying above code and managed to get it to work in other examples but not the website that I'm working with...

Any other ideas? Erel?
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…