HTTPUtil Question

walterf25

Expert
Licensed User
Longtime User
Hello everyone, i'm currently saving an xml file like this
B4X:
Sub hc3_ResponseSuccess(Response As HttpResponse, TaskId As Int)

    Response.GetAsynchronously("GetRSS3",   File.OpenOutput(File.DirDefaultExternal, "RSS3.xml", False), True, TaskId)
   
End Sub

Sub hc3_ResponseError(Response As HttpResponse, Reason As String, StatusCode As Int, TaskId As Int)

    If Response <> Null Then

       Msgbox("Error: " & Response.GetString("UTF8"), "Connection Error")

                     Response.Release
 
    End If
   
End Sub

Sub GetRSS3_StreamFinish(Success As Boolean, TaskId As Int)
   If Success = False Then

                     Msgbox(LastException.Message, "Error")
       Return
    
            End If
            
            Dim in As InputStream

            in = File.OpenInput(File.DirDefaultExternal, "RSS3.xml")

   
            
            Parser3.Parse(in, "Parser3")
            in.Close
            
            Activity.Title = "Bus Schedules:  " 
            
            ProgressDialogHide

         
End Sub

i have 4 different activities and each one saves a different xml file, i then parse the file to extract the necessary data from the files, my question is if i close the app and then re-launch it again i would expect new and refreshed data to get saved in those xml files since i'm pulling those files from an online API, for some reason when i access a schedule which gets updated every second i always receive the same data i got when i first launched the app for the first time, is there a way to delete those xml files everytime so that when you re-launch the app new ones will get created?

man, i think i just made myself dizzy trying to explain this, ;(
anyhow any help will be greatly appreciated.

cheers,
Walter
 
Last edited:

walterf25

Expert
Licensed User
Longtime User
Need Explanation

Hi Erel, the code that starts the download is in the
B4X:
Sub Activity_Create(FirstTime As Boolean)
code, one thing i noticed is that it works fine when i'm using it on my regular 3G phone connection, it updates the data everytime, also when i'm connected to my home wifi network, but here at work, i came in today in the morning and when connected to my work's wifi network again i see the old data from yeserday, this is puzzling, i'm not an expert in this type of thing but why do you think, while connected to my work's wifi network it keeps giving me the same xml file as yesterday and the day before?

Thanks,
Walter
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
XML File unexplained problem

Hello everyone, i'm still in need of some help to figure out this issue, i just simply can't understand it.
I have 4 different activities, each activity initializes a HTTP Request in the
Sub Activity_Create(FirstTime as Boolean) like this

B4X:
Sub Process_Globals
Dim hc as HttpClient
Dim req as HttpRequest
Dim MainRequestID as int
MainrequestID =1
End Sub

Sub Activity_Create(FirstTime as Boolean)
hc.Initialize
req.InitializeGet("http://xxxxxxxxxxxxxxxxxxxxxxxxxxxxx/xml/")    'there's an actual http address here.
hc.execute(req, MainRequestId)

End Sub

and then obviously i have the code that handles the response from the xml file and it saves the xml file to the phone. I also have the code that parses the xml file and extracts the needed data to display in a listview on each activity.

The issue is that when i'm connected to my work wifi network, i always get the same file over and over, but when i'm connected to my regular 4G or 3G network on my phone or even on the wifi network at home, everything works fine, i get different data every time.
I just can't figure out why this is, the API from where i'm accessing the xml files gets updated constantly, if I enter the api address in my web browser in my computer i get the correct data every time.

Can anyone please help me figure this out?

By the way I've added this code to delete the files everytime you leave one activity and go to the next but I still get and old xml file everytime.

B4X:
File.Delete(File.DirDefaultExternal, "RSS.xml")

thanks
cheers,
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
Looking at your code:
B4X:
Sub Process_Globals

Dim hc as HttpClient
Dim req as HttpRequest
Dim MainRequestID as int 'Why you have this?

MainrequestID =1 'And this?

End Sub

Sub Activity_Create(FirstTime as Boolean)

hc.Initialize 'Something missing here

req.InitializeGet("http://xxxxxxxxxxxxxxxxxxxxxxxxxxxxx/xml/")    'there's an actual http address here.

hc.execute(req, MainRequestId)

End Sub

Try this:
B4X:
Sub Process_Globals

Dim hc as HttpClient
Dim req as HttpRequest

End Sub

Sub Activity_Create(FirstTime as Boolean)

hc.Initialize("hc")

req.InitializeGet("http://xxxxxxxxxxxxxxxxxxxxxxxxxxxxx/xml/")    'there's an actual http address here.

hc.execute(req, 1)

End Sub
 
Last edited:
Upvote 0

walterf25

Expert
Licensed User
Longtime User
XML File unexplained problem

Hi NJDude yeah i'm sorry i do have that part, i just forgot to put it in my previous comment, i have it like this

B4X:
hc.Initialize("hc")

it is very weird that i get an old file even if I delete the file i always get an old xml file, this won't be a problem because obviously the users will be using my app only when they're out on the street waiting for a bus, but i still want to figure out why is it that here at work while connected to their wifi network i always get an old file, therefore i can't see the schedule update.
 
Upvote 0
Top