Android Question WebService Rest

Cristian Regazzo

Member
Licensed User
Longtime User
Good afternoon,

I need to consume a WebService Rest in my App.

I looked in the forum and did not find an example.

Someone as an example of consuming WebService Rest?

Thank you.

Cristian Regazzo
 

Cristian Regazzo

Member
Licensed User
Longtime User
Good Morning,

In my tests, I'm not using authentication to consume the WebService.

My problem is in getting the result of my WebService Rest.

For SopUI or PostMan, I get the feedback perfectly, however on Basic4Android I'm not getting it.

Checking the OkHttpClient Documentation, I should use GetAsynchronously, but one of the Event parameters is Output, however I do not want to save the result to a file.

How do I get the consumption result of the WebService Rest in the ResponseSuccess Event, since the GetString event has been deprecated.

Thank you very much.
 
Upvote 0

KMatle

Expert
Licensed User
Longtime User
I'm not getting it.

No response at all? What does Job.GetString say?

I do not respond to "false" calls, too in my php environment (so an attacker get's nothing back and does not know what's happening). Hard to say when we don't know how to call it. Is there a documentation how the call has to be done? (parms).
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Maybe you should post the URL of the rest-api you are using. (Website, documentation-site)

As @KMatle already said okHTTPutils is the way to go.

Hiding the code which you are using without success will not help us to help you fix it.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
   
    Dim Register As HttpJob
    Register.Initialize("rest", Me)
    Register.Tag = "resttest.json"
  Register.Download("http://resttst.yaskawa.com.br:9090/rest/sample")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
Sub JobDone(Job As HttpJob)
    ProgressDialogHide
  If Job.Success Then
        If Job.JobName = "rest" Then
            'Dim out As OutputStream
            'out = File.OpenOutput(File.DirRootExternal,Job.Tag,False )
            'File.Copy2(Job.GetInputStream, out)
            'out.Close
            Log($"The job resttest finished "$)
           
            ParseJSON(Job.GetString)
           
        End If
  Else
      Log( Job.ErrorMessage)
  End If
    Job.Release
End Sub
Sub ParseJSON(jsonstring As String)
    Dim parser As JSONParser
    parser.Initialize(jsonstring)
    Dim root As List = parser.NextArray
    For Each colroot As Map In root
         Dim name As String = colroot.Get("name")
         Dim id As Int = colroot.Get("id")
        Log($"${name} - ${id}"$)
    Next
End Sub
 

Attachments

  • resttest.zip
    7.1 KB · Views: 478
Upvote 0

Cristian Regazzo

Member
Licensed User
Longtime User
Good afternoon DonManfred,

Thanks a lot for the help. Worked perfectly

Just got a question, can I consume the WebService Rest using the InitializeGet command?

Thank you again,
 
Upvote 0

Cristian Regazzo

Member
Licensed User
Longtime User
Good afternoon DonManfred,

Thank you again.

It's just that I was a bit confused (I'm new to Basic4Android) because you used Register.Download, and I was trying to consume the RestServ WebService through the REST.InitializeGet ( "http://resttst.yaskawa.com.br:9090 / Rest / sample ") and using the HttpClient1.Execute (REST, 1) command.

Thank you.
 
Upvote 0
Top