HTTP or WebView...I need a code sample, Please!!!!

Cableguy

Expert
Licensed User
Longtime User
I've been struging since yesterday on how to do a "simple" task, that is to retrieve a WebPage's html source-code... From what I can see, with WebView its just not possible, so I should use http instead, but albeit all my efforts, no luck...

Can anyone post a simple example?

Thanks in advance
 

stevel05

Expert
Licensed User
Longtime User
I've just replied to your post on StackOverflow.

Steve
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
Thank you both, I will have a look at it....

Seem I have yet to understand how httputils work..especially the "callback..." subs/methods are for.
 
Upvote 0

lagore

Active Member
Licensed User
Longtime User
Hi,
If it is the HTML code that you require directly off a web site then at its most basic if you use the following code from Erel's HttpUtils example,
B4X:
Sub Globals
 Dim b4a As String
 b4a = "http://www.b4x.com"
End Sub

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

Sub JobDone (Job As String)
 Dim s As String
 If HttpUtils.IsSuccess(b4a) Then
  s = HttpUtils.GetString(b4a)
 End If
End Sub
what ever site address you set in the string "b4a" will be returned to the JobDone Sub when the site is fully loaded (not to a webview), the string "s" will contain the actual HTML code. Then you can parse this any way you want. I use this technique quite a bit to strip data from a web page and display it in a more easy to read fashion on a device. You can modify this string and then load it to a webview with
B4X:
webview1.LoadHtml(s)
I hope this is what you are looking for.
Edward
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…