Tagged: HTTP POST
- This topic has 2 replies, 3 voices, and was last updated 7 years, 8 months ago by Clayton Chow.
-
AuthorPosts
-
-
May 26, 2017 at 8:34 am #8523Aditya PhatakParticipant
Hi,
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/” 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”)
(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
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
(integration-send-receive
(message
(: :class “HTTP”)
(: url “http://localhost:7080/nexj/finance/anon/channel/HelloWorld”)
(: method “POST”)
)
“HelloWorldClient”
()
)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”/>0Attachments:
You must be logged in to view attached files. -
May 29, 2017 at 10:10 am #8538Clayton ChowParticipant
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.
0
-
-
AuthorPosts
- You must be logged in to reply to this topic.