B4J Question Http poststring with headers

Discussion in 'B4J Questions' started by Pedro Caldeira, Mar 21, 2018.

  1. Pedro Caldeira

    Pedro Caldeira Active Member Licensed User

    I am trying to send a string with a post method and some headers.
    Non Ui application

    code below

    Code:
    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)
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Why aren't you using the smart string literal???

    Make sure to reference jOkHttpUtils2_NONUI.
     
  3. Pedro Caldeira

    Pedro Caldeira Active Member Licensed User

    I am referencing jOkHttpUtils2_NONUI
    and i am going to change it to a smart string literal. but is that error due to that ?
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    No.

    Based on the error you are referencing the UI library. Maybe both are referenced?
     
  5. Pedro Caldeira

    Pedro Caldeira Active Member Licensed User

    that was the problem. thanks
     
  6. Pedro Caldeira

    Pedro Caldeira Active Member Licensed 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

    Code:
    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
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    Please start a new thread for a new question.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice