Android Question B4A to send a HTTP Post to add a row to a CakePHP table

deantangNYP

Active Member
Licensed User
Longtime User
Using Chrome debugger, the HTTP Post Form data looks like this:

B4X:
_method=POST&_method=POST&data%5BUpload%5D%5Bpicture%5D=Pic2&data%5BUpload%5D%5Bbubble_no%5D=1

The parsed version looks like this:

B4X:
_method:POST
data[Upload][picture]:Pic2
data[Upload][bubble_no]:1

How do I use Basic4Android to send this httpPost/httpJob over to add the new row to my Cakephp table?
Can you point me to a correct URL if there is any? Or provide me with a correct code for the example above? Thanks in advance.
 

nwhitfield

Active Member
Licensed User
Longtime User
It's probably easier to look at the form source code, rather than the data. There you'll see the various bits of the HTML form with thing like

B4X:
<input type="text" name="picture"></input><input type="text" name="bubble_no"></input>

Then, assuming you know the URL, you can use the PostString function; let's say you have assigned your variables as strings that match the names of the fields in the form, and the URL to a string called CakeURL, you post the data like this

B4X:
Dim j As HttpJob
j.Initialise("cake",Me)

j.PostString(CakeURL,"picture=" & picture & "&bubble_no=" & bubble_no)

You can check the result in the JobDone sub. If there are a lot of fields, you might want to build the string with StringBuilder, eg

B4X:
Dim form As StringBuilder
form.Initialize

form.Append("picture=")
form.Append(picture)
form.Append("&bubble_no=")
form.Append(bubble_no)

j.PostString(CakeURL,form.ToString)
 
Last edited:
Upvote 0

deantangNYP

Active Member
Licensed User
Longtime User

Thanks for the reply. Will give it a try.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…