Android Question Cancel web service request from DownloadService

swabygw

Active Member
Licensed User
Longtime User
I've been using the following to consume web services:

B4X:
Sub makeHttpRequest(xmlRequestString As String, jobName As String, targ As Object)
  Dim outXML As String = xmlRequestString
  Dim url As String = "http://www.myurl.com/myvbdotnet.asmx"
  Dim job1 As HttpJob
  job1.Initialize(jobName, targ)
  job1.PostString(url, outXML)
  job1.GetRequest.SetContentType("text/xml")
  job1.GetRequest.Timeout = 5000
End Sub

and the following to process the result:

B4X:
Sub processJobDone(job As HttpJob)
  If job.Success Then
  Else
  End If
End Sub

This has worked fine, but I'd like to implement a way to cancel a job. I'd like to implement the DownloadService, as suggested in this link: https://www.b4x.com/android/forum/threads/download-huge-files-with-httputils2.30220/#content

I understand that I should make the request something like this:

B4X:
Sub btnDownload_Click
  Dim dd As DownloadData
  dd.url = link1 '<--- download link dd.EventName = "dd"
  dd.Target = Me
  CallSubDelayed2(DownloadService, "StartDownload", dd)
End Sub

But I can't see how to post the outgoing XML as I did in the first method with "job1.PostString(url, outXML)". Could someone provide a simple example of how to redo Sub btnDownload_Click to send outgoing XML to a web service, plz?

Btw, I tried, after importing the three .bas files - DownloadService, HttpJob, HttpUtils2Service, to just run my existing code. It gave the following error:
- Error occurred on line: 45 (HttpUtils2Service)
- java.lang.RuntimeException: Field: CountingStream not found in: java.lang.Object
I feel fairly certain that this error is because of my prior question of how to formulate the outgoing request.
 
Last edited:

swabygw

Active Member
Licensed User
Longtime User
I changed the Type as follows:

B4X:
Type DownloadData (Text As String, url As String, Target As Object, EventName As String)

and the StartDownload call as follows:

B4X:
'J.Download(data.url)
J.PostString(data.url, data.Text)

The response was a server error: Unsupported Media Type. I've seen this error before - :) - so, fixed by amending the last bit of code to:

B4X:
'J.Download(data.url)
J.PostString(data.url, data.Text)
J.GetRequest.SetContentType("text/xml")
J.GetRequest.Timeout = 5000

And, voila - it worked. Thanks for the assistance!
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
How do I control where the file is saved for copying later?
It has nothing to do with this thread.

Create a new Thread in the Questions forum for this. AFTER you searched the forum on how to do this with okHTTPutils. There are a lot of discussions.
 
Upvote 0
Top