Home Forums Scheme Invoking a URL using HTTP POST method


Viewing 2 reply threads
  • Author
    • #8523
      Aditya PhatakAditya Phatak


      We have a specific requirement to invoke a url using HTTP POST method. I have come across the (this’ browse <url>) syntax which directly opens the <url> string (similar to window.open() in JavaScript).

      I tried to refer a code available on “https://www.mkyong.com/java/how-to-send-http-request-getpost-in-java/&#8221; and replicated it in NexJ Scheme by importing some java libraries:


      (import’ java.net.HttpURLConnection)
      (import’ java.net.URL)
      (import’ java.io.DataOutputStream)

      (define baseurl “https://www.google.co.in&#8221;)
      (define connection java.net.HttpURLConnection)

      ; Constructing an object of url:
      (define url (java.net.URL’new baseurl))

      ; Typecast into HttpURLConnection the above url object:
      (define httpCon (connection’cast (url’openConnection)))

      After this, when I try using the setRequestMethod function of the java class, it gives an error:

      ((connection’cast (url’openConnection))’setRequestMethod “POST”)

      ;Error: Attempt to invoke an unknown method “setRequestMethod” on class “sun.net.www.protocol.http.HttpURLConnection”.


      This is required by the integration to make sure we comply with the security policies requested. Is there a way to achieve this through NexJ Scheme script?

    • #8530
      Owen PondOwen Pond

      Hi Aditya,

      Normally we use the (integration-send-receive) function to use the POST method via HTTP. You will need to create a channel to send the request on and add that channel to your environment.

      For example; if you want to call a HelloWorld service, you can write something like

      (: :class “HTTP”)
      (: url “http://localhost:7080/nexj/finance/anon/channel/HelloWorld&#8221;)
      (: method “POST”)

      There is an HTTP message definition in your repository where you can see how to set headers and other properties of your HTTP message.

      I’ve attached a simple hello world service to this post so that you can test this code. Please make sure to include the provided channels in your environment under channel connections by including the following.
      <HTTPConnection authentication=”none” channel=”HelloWorld”/>
      <HTTPConnection channel=”HelloWorldClient”/>


      You must be logged in to view attached files.
    • #8538
      Clayton ChowClayton Chow

      Hi Owen,

      Just to clarify Aditya’s requirement/question:

      • The user would like to click on a link in the UI and open up a new Internet Browser using a POST message.


      Based on that, I’m not sure if “integration-send-receive” will work – please correct me if I am wrong:

      • it is a server-side function
      • it sends/receives the HTTP message outside the Web Browser and therefore not apparent to the login user.




Viewing 2 reply threads
  • You must be logged in to reply to this topic.