B4J Question HTTP post error

StarinschiAndrei

Active Member
Licensed User
Longtime User
Hi everyone,
Could you please help me with the following error?
I try to post with the below code :
B4X:
Sub Button1_Click
    Submit_Action
End Sub
Sub Submit_Action
    Dim j As HttpJob
    j.Initialize("",Me )
    j.PostString("http://localhost:4444/SellPLUWithSpecifiedVat(NamePLU=Article1,OptionVATClass=A,Price=10.2,Quantity=1, DiscAddP = 0, DiscAddV = 0)","")
    'j.GetRequest.SetContentType("application/json")
    Wait For(j) JobDone(j As HttpJob)
    If j.Success Then
        Log(j.GetString)
    End If  
    j.Release
End Sub
this is the error that i get (from browser the link works fine):

Program started.
<Res Code="63">
<Err Source="Server" Type="ClientInvalidPostFormat">
<Message>Root element is missing.
Content of post body must be valid xml. </Message>
</Err>
</Res>
 

EnriqueGonzalez

Expert
Licensed User
Longtime User
Content of post body must be valid xml.
the server is expecting and XML and you are providing an empty string

SellPLUWithSpecifiedVat(NamePLU=Article1,OptionVATClass=A,Price=10.2,Quantity=1, DiscAddP = 0, DiscAddV = 0)
you cant put parenthesis and spaces in a URL,
you have to create an xml and pass these values there not in the URL
 
Upvote 0

StarinschiAndrei

Active Member
Licensed User
Longtime User
If it is from the browser then use a GET request (j.download)
i don't think that solution is with GET. i should generare a link exactly the same that i sent previously an post.
In the below image you can see what happen from browser.
1676386716166.png
 
Upvote 0

StarinschiAndrei

Active Member
Licensed User
Longtime User
Yes. you wrote the URL and issued a GET request, the server responded with an XML string
Below a short description from documentation.
Development/Testing without using auto-generated library
If a library for specific language is not provided, fiscal device operations can be performed by sending HTTP GET request to ZFPLabServer. The server might be running locally or remotely.
API docs and test environment can be found at the following url location: http://localhost:4444
The end user software sends commands in the format: http://ip:4444/command
Examples:
http://localhost:4444/SellPLUWithSpecifiedVat(NamePLU=Article1,OptionVATClass=B,Price=1.2,Quantity=2, DiscAddP = 5, DiscAddV = 0)
 
Upvote 0

alwaysbusy

Expert
Licensed User
Longtime User
What does this return?

B4X:
Dim command As String = "SellPLUWithSpecifiedVat(NamePLU=Article1,OptionVATClass=A,Price=10.2,Quantity=1, DiscAddP = 0, DiscAddV = 0)"
Dim su As StringUtils
command = su.EncodeUrl(command, "UTF-8")
    
Dim j As HttpJob
j.Initialize("",Me )
j.Download("http://localhost:4444/" & command)
Wait For(j) JobDone(j As HttpJob)
If j.Success Then
     Log(j.GetString)
End If
j.Release
 
Upvote 0

StarinschiAndrei

Active Member
Licensed User
Longtime User
Yeah, I would remove the spaces too. Just left them in there as the API seems to allow them, but I would not do it either.
i removed the space
B4X:
    j.PostString("http://localhost:4444/OpenReceipt(OperNum=1,OperPass=0)","")
and also with , i got the same error.
B4X:
j.PostString("http://localhost:4444/",$"OpenReceipt(OperNum=1,OperPass=0)"$)
<Res Code="63">
<Err Source="Server" Type="ClientInvalidPostFormat">
<Message>Root element is missing.
Content of post body must be valid xml. </Message>
</Err>
</Res>
 
Last edited:
Upvote 0

StarinschiAndrei

Active Member
Licensed User
Longtime User
What does this return?

B4X:
Dim command As String = "SellPLUWithSpecifiedVat(NamePLU=Article1,OptionVATClass=A,Price=10.2,Quantity=1, DiscAddP = 0, DiscAddV = 0)"
Dim su As StringUtils
command = su.EncodeUrl(command, "UTF-8")
   
Dim j As HttpJob
j.Initialize("",Me )
j.Download("http://localhost:4444/" & command)
Wait For(j) JobDone(j As HttpJob)
If j.Success Then
     Log(j.GetString)
End If
j.Release
Sorry ,
Here is the error :
WARNING: package com.sun.javafx.embed.swing.oldimpl not in javafx.swing
Waiting for debugger to connect...
Program started.
<Res Code="11">
<Err Source="Server" Type="ServArgDefMissing">
<Message>attribute name +DiscAddP+ not found in server definitions</Message>
</Err>
</Res>
 
Upvote 0
Top