Hi, I’m a novice with the okHttpUtils and the HttpServer libraries, but hoping for advice please. (the libraries seem to be excellent and just what I need - if I knew how to use them!)
I would like to request a series of variables (e.g.Key1, Key2) from another Android device running the HttpServer library. If I use 'download2', what should the server code look like to send the data back, and what code is needed on the requesting device to recieve it please? I tried using Response.SendString("Key1=Value1&Key2=Value2") on the server, and then Job.GetString on the requesting device. This works but then requires me to disassemble the string manually. I'm suspecting there is a neater way already built into the functions of the library that would give me the variables directly?
Many thanks for any help you can offer.
Code extracts for info
On the requesting device, I added ‘GetData’ to the URI and then add ‘User1’, ‘User2’ or ‘User3’ to tell the server which device is requesting information. Then on the server I look for URIs starting with ‘GetData’ and send back different data based on with user made the request.
Code on requesting device
Sub Button_Get_Click
Dim job4 As HttpJob
job4.Initialize("Job4", Me)
job4.Download2("http://192.168.0.45:5555/GetData/User1",Array As String("Key1", "value1", "Key2", "value2"))
End Sub
Sub JobDone(Job As HttpJob)
If Job.Success = True Then
Dim s As String
s = Job.GetString
Label1.Text = s
End If
End Sub
Code on server
Sub Server_HandleRequest (Request As ServletRequest, Response As ServletResponse)
Select True
Case Request.RequestURI.StartsWith("/GetData/")
HandleGetData(Request,Response)
End Select
End Sub
Sub HandleGetData (Request As ServletRequest,Response As ServletResponse)
Dim UserName As String = DecodePath(Request.RequestURI.SubString("/GetData/".Length))
Response.SetContentType("text/html")
Select True
Case UserName = "User1"
Response.SendString("Key1=Value1&Key2=Value2")
End Select
End Sub
I would like to request a series of variables (e.g.Key1, Key2) from another Android device running the HttpServer library. If I use 'download2', what should the server code look like to send the data back, and what code is needed on the requesting device to recieve it please? I tried using Response.SendString("Key1=Value1&Key2=Value2") on the server, and then Job.GetString on the requesting device. This works but then requires me to disassemble the string manually. I'm suspecting there is a neater way already built into the functions of the library that would give me the variables directly?
Many thanks for any help you can offer.
Code extracts for info
On the requesting device, I added ‘GetData’ to the URI and then add ‘User1’, ‘User2’ or ‘User3’ to tell the server which device is requesting information. Then on the server I look for URIs starting with ‘GetData’ and send back different data based on with user made the request.
Code on requesting device
Sub Button_Get_Click
Dim job4 As HttpJob
job4.Initialize("Job4", Me)
job4.Download2("http://192.168.0.45:5555/GetData/User1",Array As String("Key1", "value1", "Key2", "value2"))
End Sub
Sub JobDone(Job As HttpJob)
If Job.Success = True Then
Dim s As String
s = Job.GetString
Label1.Text = s
End If
End Sub
Code on server
Sub Server_HandleRequest (Request As ServletRequest, Response As ServletResponse)
Select True
Case Request.RequestURI.StartsWith("/GetData/")
HandleGetData(Request,Response)
End Select
End Sub
Sub HandleGetData (Request As ServletRequest,Response As ServletResponse)
Dim UserName As String = DecodePath(Request.RequestURI.SubString("/GetData/".Length))
Response.SetContentType("text/html")
Select True
Case UserName = "User1"
Response.SendString("Key1=Value1&Key2=Value2")
End Select
End Sub