Hi all,
This is hopefully the last set of code of my scanning app to get working - posting the scanned data in JSON format back to the web service...
I'm using this code to do the post job, but it is continually failing with 500 internal server error.
Can someone please look it over?
What I'm not sure of is what is the correct way to setup the server to accept POSTS?
All GET's work fine to the same URL.
BTW: I'm in great appreciation of all the submits of code from so many talented people on this forum
This is hopefully the last set of code of my scanning app to get working - posting the scanned data in JSON format back to the web service...
I'm using this code to do the post job, but it is continually failing with 500 internal server error.
Can someone please look it over?
What I'm not sure of is what is the correct way to setup the server to accept POSTS?
All GET's work fine to the same URL.
BTW: I'm in great appreciation of all the submits of code from so many talented people on this forum
B4X:
'this is a resumable sub with the Wait For line of code
Sub btnPostJSON_Click
'get first TOP 20 records for testing
Dim strSQL As String = "SELECT ScanID, HID, PLU, Description, Qty, ItemPrice, UserID, CreateDateTime FROM ScanDetail WHERE UploadDateTime is Null ORDER BY HID LIMIT 20"
Dim cur As Cursor
Dim L1 As List
Dim M1 As Map
L1.Initialize
DateTime.DateFormat = "yyyy-MM-dd"
Try
cur = SQL.ExecQuery(strSQL)
For i = 0 To cur.RowCount - 1
cur.Position = i
M1.Initialize
M1.Put("hid", cur.GetInt("HID"))
M1.Put("plu", cur.GetString("PLU"))
M1.Put("description",cur.GetString("Description"))
M1.Put("qty", cur.GetInt("Qty"))
M1.Put("price", cur.GetDouble("ItemPrice"))
M1.Put("userid", cur.GetString("UserID"))
M1.Put("scandatetime", DateTime.Date(cur.GetString("CreateDateTime")) & " " & DateTime.Time(cur.GetString("CreateDateTime")))
L1.Add(M1)
Next
Dim gen As JSONGenerator
gen.Initialize2(L1)
Dim jsn As String
jsn = gen.ToPrettyString(2)
Dim HJ As HttpJob
HJ.Initialize("PostScanDet",Me)
'we use Alpha Anywhere application for GETS and POSTS as the web service host app,
'hence the .a5w in the URL
HJ.PostString("http://ServerNameHere:PortNumberHere/PostJSONData.a5w",jsn)
'Resumable Sub code:
Wait For (HJ) JobDone(HJ As HttpJob)
If HJ.Success Then
Select HJ.JobName
Case "PostScanDet"
Log(HJ.JobName)
Dim res As String = HJ.GetString
Log(res)
End Select
Else
Log(HJ.ErrorMessage)
End If
Catch
Log(LastException)
End Try
cur.Close
End Sub