B4R Question Byte() to string, string to byte in http request

petr4ppc

Well-Known Member
Licensed User
Longtime User
Dear friends , please, I have code:

B4X:
dim a() as byte
a=byteconvert.StringFromBytes(Queue.FirstItem)
Log(a) 'here I see the expected number, for example: 1234
gotoweb(a)

Sub gotoweb (a() As Byte)       '  Sub gotoweb (a() As string)   '  declaration "Sub gotoweb(a() as string)" is not functioned. I get the same error as with: a() as byte
    Log(a) 'here I see the expected number, for example: 1234
    Dim nr As String =a       ' when i use this , then http request is not NOT FUNCTIONED
     ' Dim nr As String ="1234"  ' but when I use this row (declaration), then http request is FUNCTIONED perfectly
    HttpJob.Initialize("x")
    Dim string() As Byte ="http://www.abc.com/go.php?a="
    string=JoinBytes(Array(string,nr.getbytes))           'NOT FUNCTIONED with Dim nr As String =a
    'string=JoinBytes(Array(string,nr))                         'NOT FUNCTIONED with Dim nr As String =a
    log(string)    ' here I see "http://www.abc.com/go.php?a=1234"  which is functioned in explorer, but it is not functioned in ESP (wth declaration: Dim nr As String =a)
    HttpJob.AddHeader("Content-Type", "application/x-www-form-urlencoded")
    HttpJob.Post(string,"")
End Sub

After HttpJob.Post(string,"") ESP module is
A) restarted, I see in terminal(in logs) this error:
rst cause:4
wdt reset
or
B) I get from JobDone "NOK"
B4X:
    If Job.JobName="x" Then
        If Job.Success Then
                Log("OK")
            Else
                Log("NOK")
                 Log("ErrorMessage: ", Job.ErrorMessage)
                 Log("Status: ", Job.Status)
                 Log(Job.Response)   
        End If
    End If
JobName: x
NOK
ErrorMessage:
Status: 400
<html>
<head><title>400 Bad Request</title></head>
<body>
<center><h1>400 Bad Request</h1></center>
<hr><center>nginx</center>
</body>
</html>
but the address for demonstrating: http://www.abc.com/go.php?a=1234 in chrome explorer is functioned..
or
C) Everything is OK as I decribed only if I use row: ' Dim nr As String ="1234" ' when I use this row (declaration), then http request is FUNCTIONED perfectly

I am sending pic with complete error description (but I think, some informations described on pic are not important, because the reason why code is not functioned I am describing directly in the code)
what I am doing wrong, please?
Best regards
pppc

I am watching:
but I can not fing solution
 

Attachments

  • 1725743905007.png
    1725743905007.png
    4.9 KB · Views: 43
Last edited:

petr4ppc

Well-Known Member
Licensed User
Longtime User
Dear Erel, dear friends,

edit of text is done.
Please for advice, what I am doing wrong.

Best regards,
p4ppc
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

RJB

Active Member
Licensed User
Longtime User
Shouldn't that be :

B4X:
Dim a as string
Dim BC as byte ByteConverter
    a = BC.StringFromBytes(Queue.FirstItem)
gotoweb(a)

Sub gotoweb (a As String)
 
Upvote 0
Top