Tagged: HTTP POST
May 26, 2017 at 8:34 am #8523Aditya PhatakParticipant
I tried to refer a code available on “https://www.mkyong.com/java/how-to-send-http-request-getpost-in-java/” and replicated it in NexJ Scheme by importing some java libraries:
(define baseurl “https://www.google.co.in”)
(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?0
May 26, 2017 at 4:21 pm #8530Owen PondParticipant
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”)
(: 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”/>
Attachments:You must be logged in to view attached files.
May 29, 2017 at 10:10 am #8538Clayton ChowParticipant
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.
- You must be logged in to reply to this topic.