It is better to put the Dim line inside the loop however it is not related to this issue.
Maybe you need to set the request content type to application/json.
That's it. A great tool for testing JSON.
It looks like PostMan can generate source code for requests (not from personal experience, just what I gleaned from the site). Could you generate such source code and post it here? I don't think the language matters much, I just would like to see how the data is posted/submitted.That's it. A great tool for testing JSON.
<%a5
dim cn as sql::Connection
dim txt as c
txt = request.Body
if cn.Open("::Name::InvJSON") then
'executes the stored procedure with the request JSON data
cn.Execute("exec Add_ScanDet @json='"+ txt +"'")
'returns the response success result:
responseJson = "{ \"items\" : [{ \"RecordsInserted\": \"ok\" }] }"
? json_reformat( responseJson )
else
'returns the error text:
dim resp.error as c = cn.CallResult.Text
? json_generate(resp)
end if
%>
[
{
"hid": 506,
"plu": "000630135615",
"description": "TOO TARTS LIQUID CNDY",
"qty": 1,
"price": 3.99,
"userid": "mark.stuart",
"scandatetime": "2017-08-02 11:22:07.089"
},
{
"hid": 506,
"plu": "000630135615",
"description": "TOO TARTS LIQUID CNDY",
"qty": 1,
"price": 3.99,
"userid": "mark.stuart",
"scandatetime": "2017-08-02 11:24:44.443"
}
]
Alpha Anywhere to PostMan response data:
{
"items": [
{
"RecordsInserted": "ok"
}
]
}
Looking at the original post (link in your initial post here), you never used the Username and Password properties of HTTPJob. These two properties will set up the Authorization header for you. Maybe that has been your problem all along.Authorization: Basic bWFyay5zdHVhcnQ6UGFsYWNlMjAxNw==
Hi Oliver,It looks like PostMan can generate source code for requests (not from personal experience, just what I gleaned from the site). Could you generate such source code and post it here? I don't think the language matters much, I just would like to see how the data is posted/submitted.
No, I'm aware of your original post and the B4A code. Postman can generate code for the request it generates (at least that is what their site says). If possible, let it generate the code (pick any language) and post it here.If you're referring to B4A code
Are you sure it's the size of the data, or not just something (a special character, for example) that only occurs a certain way into your dataset that is causing the problem?
An error 500 might occurr, for example, if there's an unescaped quote mark in the data, which causes the parsing of the JSON to fail horribly. It's also possible that there may be a per-script maximum memory limit or maximum post size specificed (eg, Apache's LimitBodyRequest directive)
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)
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
'
' Add the authentication here
HJ.Username = "someusername"
HJ.Password = "averysecurepassword"
HJ.PostString("http://ServerNameHere:PortNumberHere/PostJSONData.a5w",jsn)
'
' Add content type here (if necessary. It may already be plain/text)
HJ.GetRequest.SetContentType("text/plain")
'Resumable Sub code:
Wait For (HJ) JobDone(HJ As HttpJob)
Hi Oliver,No, I'm aware of your original post and the B4A code. Postman can generate code for the request it generates (at least that is what their site says). If possible, let it generate the code (pick any language) and post it here.
From your original post:
TryB4X: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)
B4X: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 ' ' Add the authentication here HJ.Username = "someusername" HJ.Password = "averysecurepassword" HJ.PostString("http://ServerNameHere:PortNumberHere/PostJSONData.a5w",jsn) ' ' Add content type here (if necessary. It may already be plain/text) HJ.GetRequest.SetContentType("plain/text") 'Resumable Sub code: Wait For (HJ) JobDone(HJ As HttpJob)
Still would like a code sample from PostMan though.
Are you sure it's the size of the data, or not just something (a special character, for example) that only occurs a certain way into your dataset that is causing the problem?
An error 500 might occurr, for example, if there's an unescaped quote mark in the data, which causes the parsing of the JSON to fail horribly. It's also possible that there may be a per-script maximum memory limit or maximum post size specificed (eg, Apache's LimitBodyRequest directive)
--Scan 1 item.
[
{
"hid": 1783,
"plu": "012000151163",
"qty": 1,
"price": "3.74",
"userid": "mark",
"scandatetime": "2017-10-20 12:12:07.012"
}
]
*** Service (httputils2service) Create ***
** Service (httputils2service) Start **
--Successfully posted from B4A app to web service.
--Web service response:
{
"items": [
{
"RecordsInserted": "ok"
}
]
}
** Activity (uploadscandetail) Pause, UserClosed = true **
** Activity (setup) Resume **
** Activity (setup) Pause, UserClosed = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (scan) Create, isFirst = false **
** Activity (scan) Resume **
** Activity (scan) Pause, UserClosed = false **
** Activity (scan) Create, isFirst = false **
** Activity (scan) Resume **
** Activity (scan) Pause, UserClosed = false **
** Activity (scan) Create, isFirst = false **
** Activity (scan) Resume **
** Activity (scan) Pause, UserClosed = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (setup) Create, isFirst = false **
** Activity (setup) Resume **
** Activity (setup) Pause, UserClosed = false **
** Activity (uploadscandetail) Create, isFirst = false **
** Activity (uploadscandetail) Resume **
--Trying 7 records, which are all the same PLU item.
--It will fail with 500 internal server error.
--Following JSON character count: 1151
[
{
"hid": 1783,
"plu": "012000151163",
"qty": 1,
"price": "3.74",
"userid": "mark",
"scandatetime": "2017-10-20 12:14:17.821"
},
{
"hid": 1783,
"plu": "012000151163",
"qty": 1,
"price": "3.74",
"userid": "mark",
"scandatetime": "2017-10-20 12:14:18.445"
},
{
"hid": 1783,
"plu": "012000151163",
"qty": 1,
"price": "3.74",
"userid": "mark",
"scandatetime": "2017-10-20 12:14:19.076"
},
{
"hid": 1783,
"plu": "012000151163",
"qty": 1,
"price": "3.74",
"userid": "mark",
"scandatetime": "2017-10-20 12:14:19.696"
},
{
"hid": 1783,
"plu": "012000151163",
"qty": 1,
"price": "3.74",
"userid": "mark",
"scandatetime": "2017-10-20 12:14:20.359"
},
{
"hid": 1783,
"plu": "012000151163",
"qty": 1,
"price": "3.74",
"userid": "mark",
"scandatetime": "2017-10-20 12:14:21.260"
},
{
"hid": 1783,
"plu": "012000151163",
"qty": 1,
"price": "3.74",
"userid": "mark",
"scandatetime": "2017-10-20 12:14:23.341"
}
]
ResponseError. Reason: Internal Server Error, Response: <!DOCTYPE html>
<html><head>
<title>500 Internal Server Error</title>
</head><body>
<h1>500 Internal Server Error</h1>
The server encountered a fatal error processing this request and could not continue.
<p>
<hr>
<address>Alpha Anywhere Application Server Application Server/12.0 Build/4119-4825 at SAV-APP1 Port 80</address>
</body></html>
** Activity (uploadscandetail) Pause, UserClosed = true **
** Activity (setup) Resume **
** Activity (setup) Pause, UserClosed = false **
** Activity (scanneditemsview) Create, isFirst = false **
** Activity (scanneditemsview) Resume **
** Activity (scanneditemsview) Pause, UserClosed = true **
** Activity (setup) Resume **
** Activity (setup) Pause, UserClosed = false **
** Activity (uploadscandetail) Create, isFirst = false **
** Activity (uploadscandetail) Resume **
--I then deleted one record, making 6 records.
--All the same PLU items.
--Post works fine.
--Following JSON character count: 987
[
{
"hid": 1783,
"plu": "012000151163",
"qty": 1,
"price": "3.74",
"userid": "mark",
"scandatetime": "2017-10-20 12:14:17.821"
},
{
"hid": 1783,
"plu": "012000151163",
"qty": 1,
"price": "3.74",
"userid": "mark",
"scandatetime": "2017-10-20 12:14:18.445"
},
{
"hid": 1783,
"plu": "012000151163",
"qty": 1,
"price": "3.74",
"userid": "mark",
"scandatetime": "2017-10-20 12:14:19.696"
},
{
"hid": 1783,
"plu": "012000151163",
"qty": 1,
"price": "3.74",
"userid": "mark",
"scandatetime": "2017-10-20 12:14:20.359"
},
{
"hid": 1783,
"plu": "012000151163",
"qty": 1,
"price": "3.74",
"userid": "mark",
"scandatetime": "2017-10-20 12:14:21.260"
},
{
"hid": 1783,
"plu": "012000151163",
"qty": 1,
"price": "3.74",
"userid": "mark",
"scandatetime": "2017-10-20 12:14:23.341"
}
]
{
"items": [
{
"RecordsInserted": "ok"
}
]
}
** Activity (uploadscandetail) Pause, UserClosed = true **
** Activity (setup) Resume **
** Activity (setup) Pause, UserClosed = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
HJ.Username = "someusername"
HJ.Password = "averysecurepassword"
HJ.PostString("http://ServerNameHere:PortNumberHere/PostJSONData.a5w",jsn)
'Add content type here (if necessary. It may already be plain/text)
'The following line requires the OkHttp library to be selected, else you will not see the .SetContentType option.
HJ.GetRequest.SetContentType("plain/text") 'THIS LINE IS IMPORTANT
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?