Android Question Downloadinf file FORBIDDEN

AlpVir

Well-Known Member
Licensed User
Longtime User
My app downloads an XML file to a certain URL but in the sub
Sub HC_ResponseError (Reason As String, StatusCode As Int, TaskId As Int)
of DownloadService.bas
"Reason" is equal to FORBIDDEN and StatusCode = 403.
It would seem a folder permissions problem but, using a PC and Firefox, you can normally download it to the same URL.
Why ?
How to overcome it ?
 

AlpVir

Well-Known Member
Licensed User
Longtime User
Using OkHttpUtils2 the error is as follows

httpjob_download (B4A line: 120)
req.InitializeGet(Link)
java.lang.IllegalArgumentException: unexpected url: www.itcbonelli.gov.it/~orario/oraedt.xml
at okhttp3.Request$Builder.url(Request.java:142)
at anywheresoftware.b4h.okhttp.OkHttpClientWrapper$OkHttpRequest.InitializeGet(OkHttpClientWrapper.java:392)
at anywheresoftware.b4a.samples.httputils2.httpjob._download(httpjob.java:112)
at anywheresoftware.b4a.samples.httputils2.main._activity_create(main.java:372)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:186)
at anywheresoftware.b4a.samples.httputils2.main.afterFirstLayout(main.java:102)
at anywheresoftware.b4a.samples.httputils2.main.access$000(main.java:17)
at anywheresoftware.b4a.samples.httputils2.main$WaitForLayout.run(main.java:80)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5264)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:900)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:695)

It may be that in the url there is one "~" ?
With "normal" url on other sites, there is no download problem, either with DownloadService or with OkHttpUtils2.

EDIT:
Not even using
B4X:
URL="www.itcbonelli.gov.it/~orario/oraedt.xml"
    url2=su.EncodeUrl(URL, "UTF8")
    job.Download(url2)
 
Last edited:
Upvote 0

KMatle

Expert
Licensed User
Longtime User
This works:

B4X:
Dim TestJ As HttpJob
    TestJ.Initialize("TestJob", Me)
    TestJ.Download("http://www.itcbonelli.gov.it/~orario/oraedt.xml")

Result:

B4X:
<PERIODICITA>S</PERIODICITA>
<SPECIFICA>ss</SPECIFICA>
<CO-DOC.>N</CO-DOC.>
<COEFF.>60/60</COEFF.>
<GIORNO>venerdì</GIORNO>
<O.INIZIO>12h00</O.INIZIO>
<SEDE>Principale (PALESTRA)</SEDE>
....

Reason:

Download2 escapes the parameters, Download doesn't
 
Upvote 0
Top