B4J Question Http poststring with headers

Pedro Caldeira

Active Member
Licensed User
Longtime User
I am trying to send a string with a post method and some headers.
Non Ui application

code below

B4X:
Dim ListaBill As List
ListaBill.Initialize
ListaBill.Add("<?xml version='1.0'?>")
ListaBill.Add("<methodCall>")
ListaBill.Add("<methodName>RequestServer.RequestBill</methodName>")
ListaBill.Add("<params>")
ListaBill.Add("<param>")
ListaBill.Add("<value>")
ListaBill.Add("<i4>" & Mesa & "</i4>")
ListaBill.Add("</value>")
ListaBill.Add("</param>")
ListaBill.Add("<param>")
ListaBill.Add("<value>")
ListaBill.Add("<i4>" & Empregado & "</i4>")
ListaBill.Add("</value>")
ListaBill.Add("</param>")
ListaBill.Add("</params>")
ListaBill.Add("</methodCall>")
String2Send=""

For x=0 To ListaBill.Size -1
      String2Send=String2Send & ListaBill.Get(x)
Next

'Private RequestServer As HttpJob - in globals
''RequestServer.Initialize("",Me) - in AppStart

RequestServer.PostString("http://192.168.0.202:8080/RPC3",String2Send)
RequestServer.Username ="username"
RequestServer.Password = "password"
RequestServer.GetRequest.SetHeader("X-ServiceAuthorization","")
Log("http://" & Ip_Address & ":" & Port_Number & "/RPC3" & CRLF & String2Send)


i Get the following error. why ? what am i missing ?

Waiting for debugger to connect...
Program started.
Error occurred on line: 62 (Main) the poststring line
java.lang.IllegalStateException: Toolkit not initialized
at com.sun.javafx.application.PlatformImpl.runLater(PlatformImpl.java:273)
at com.sun.javafx.application.PlatformImpl.runLater(PlatformImpl.java:268)
at javafx.application.Platform.runLater(Platform.java:83)
at anywheresoftware.b4j.objects.FxBA.postRunnable(FxBA.java:17)
at anywheresoftware.b4a.keywords.Common.CallSubDelayed4(Common.java:520)
at anywheresoftware.b4a.keywords.Common.CallSubDelayed2(Common.java:504)
at b4j.example.httpjob._postbytes(httpjob.java:272)
at b4j.example.httpjob._poststring(httpjob.java:409)
at b4j.example.main._talk2winrest(main.java:193)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:613)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:228)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:159)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:90)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:93)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:77)
at b4j.example.main.main(main.java:29)
 

Pedro Caldeira

Active Member
Licensed User
Longtime User
Erel,
Now works but i can't get the headers from the response.
I recall that you provided a code to replace in the Httputils source to expose the headers, but how can i do it in non UI app ?

code provided by you

B4X:
Sub hc_ResponseSuccess (Response As HttpResponse, TaskId As Int)
   Dim job As HttpJob = TaskIdToJob.Get(TaskId)
   job.Tag = Response.GetHeaders
   
   Response.GetAsynchronously("response", File.OpenOutput(TempFolder, TaskId, False), _
     True, TaskId)
End Sub
 
Upvote 0
Top