Hey guys, hope you're doing well.
I want to create an application to post some JSON data to an endpoint and get a field from the returned response. Whenever I click the button it takes back with the "Bad Request" error and says that two "title" and "script" fields are required. (I've already filled them up)
It really ticks me off. The endpoint takes two required fields. Title and Script. (It also takes some optional fields)
In spite, I made a completed JSON variable, it does not work.
Here is my code:
B4X:
Dim data As Map = CreateMap("title": edt_title.Text, "detail": edt_detail.Text, "script": edt_script.Text, "language": ac_language.Text)
Dim json As JSONGenerator
json.Initialize(data)
Dim connection As HttpJob
connection.Initialize("Connection", Me)
connection.PostString("http://codehub.pythonanywhere.com/api/v1/snippet/", json.ToString)
connection.GetRequest.SetHeader("Content-Type", "application/json")
ToastMessageShow("Created",True)
This is the scenario that I want to implement. The user should fill some fields and the program should post those data in a JSON-styled form to the endpoint. Then, the webserver responses back a JSON data and I need to chop it and take the "link" field from it.
Downloading resources is simpler with the new Resumable Subs feature. Using Wait For we can wait for the JobDone event in the same sub that started the download. No longer is it needed to have a single sub that handles all requests results. Simplest example: Dim j As HttpJob j.Initialize(""...