Sub Process_Globals
Dim AuthCookie As String=""
Dim HttpClient1 As HttpClient
Dim TaskId As Int=0
End Sub
Sub Service_Create
HttpClient1.Initialize("HttpClient1")
End Sub
Sub Service_Start (StartingIntent As Intent)
If AuthCookie="" Then
Dim HttpRequest1 As HttpRequest
Dim LoginUrl As String="set your web site url here"
Dim PostData As String="username=???&password=???"
HttpRequest1.InitializePost2(LoginUrl, PostData.GetBytes("UTF8"))
HttpClient1.Execute(HttpRequest1, TaskId)
TaskId=TaskId+1
End If
End Sub
Sub Service_Destroy
End Sub
Sub HttpClient1_ResponseError (Response As HttpResponse, Reason As String, StatusCode As Int, TaskId1 As Int)
Log("HttpClient1_ResponseError")
Log("TaskId: "&TaskId1&", Reason: "&Reason&", Code: "&StatusCode)
If Response<>Null Then
Log(Response.GetString("UTF8"))
Response.Release
End If
End Sub
Sub HttpClient1_ResponseSuccess (Response As HttpResponse, TaskId1 As Int)
Log("HttpClient1_ResponseSuccess")
Log("TaskId: "&TaskId1)
Log("** Headers **")
Dim Headers As Map=Response.GetHeaders
Dim i As Int
Dim Key, Value As String
For i=0 To Headers.Size-1
' one of these key/value pairs should be the logged in session cookie
Key=Headers.GetKeyAt(i)
Value=Headers.GetValueAt(i)
Log(Key&" : "&Value)
Next
' ** watch out - if these next lines are uncommented a NetworkOnMainThread exception will occur **
' set SDK target to API 8 as temporary workaround
' Log("** Response **")
' If Response<>Null Then
' Log(Response.GetString("UTF8"))
' Response.Release
' End If
End Sub