How to send data to a form using HTTP?

susu

Well-Known Member
Licensed User
Longtime User
I want to send data to a form (Http Post method). I guess it's
B4X:
InitializePost2 (URL As String, Data() As Byte)
but I don't know how to declare Data() as Byte.
 

susu

Well-Known Member
Licensed User
Longtime User
I'm stuck!
:sign0085: Please!
 
Upvote 0

susu

Well-Known Member
Licensed User
Longtime User
Thanks Agraham, I tried to convert string to byte already but it doesn't work. I also found the code below but no better luck.

Dim url As String
Dim myHttpRequest As HttpRequest
url = "https://yourURLhere.html"
Dim str() As Byte
Dim form As String
form = "usernme=max&Country=Vienna&Telephone=123456"
str = form.GetBytes("UTF8")
myhttprequest.InitializePost2(url,str)
myHttpRequest.Timeout = 5000

http://www.b4x.com/forum/basic4android-getting-started-tutorials/6510-http-form-post.html

I need to dig more :(
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Your code looks correct.
Here is a similar code that works:
B4X:
Sub Process_Globals
    Dim hc As HttpClient
End Sub
Sub Globals

End Sub
Sub Activity_Create(FirstTime As Boolean)
    If FirstTime Then
        hc.Initialize("hc")
    End If
    Dim req As HttpRequest
    req.InitializePost2("http://www.b4x.com/print.php", "user=erel&animal=cat".GetBytes("UTF8"))
    hc.Execute(req, 1)
End Sub
Sub hc_ResponseError (Reason As String, StatusCode As Int, TaskId As Int)
    Msgbox(reason, "error")
End Sub
Sub hc_ResponseSuccess (Response As HttpResponse, TaskId As Int)
    Msgbox(Response.GetString("UTF8"), "success")
End Sub
 
Upvote 0

susu

Well-Known Member
Licensed User
Longtime User
Yes, your code works that mean my code doesn't. Thank you Erel.
 
Upvote 0

susu

Well-Known Member
Licensed User
Longtime User
Did InitializePost2 support cookie/session ? If yes, how can I deal with it?
 
Upvote 0
Top