I'm a newbe in the world of android as well as B4A.
I want to send login information, ID and Pass to a pre specified URL in POST method.
I read some article HttpRequest to perform this job.
The snippet is"
Now can anyone please help me to play with JSON response?
I want to send login information, ID and Pass to a pre specified URL in POST method.
I read some article HttpRequest to perform this job.
The snippet is"
B4X:
'Activity module
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim url As String
Dim usern As String
Dim passn As String
Dim param As String
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim UserName As EditText
Dim Login As Button
Dim Password As EditText
Dim hc As HttpClient
Dim req As HttpRequest
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("jsonapp")
If FirstTime Then
hc.Initialize("hc")
End If
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Login_Click
url = "http://domain.com/jsonapp.php"
usern = UserName.Text
passn = Password.Text
param = "user="& usern &"&pass="& passn
req.InitializePost2(url, param.GetBytes("UTF8"))
hc.Execute(req, 1)
End Sub
Sub hc_ResponseError (Reason As String, StatusCode As Int, TaskId As Int)
Msgbox(Reason, "error")
End Sub
Sub hc_ResponseSuccess (Response As HttpResponse, TaskId As Int)
Msgbox(Response.GetString("UTF8"), "success")
End Sub
Now can anyone please help me to play with JSON response?
Last edited: