Mathematica 8.0 interacting with a JSP web server using HTTP POST and XML

I was instructed to use Mathematica to interact with a third-party web server via JSP using HTTP POST and XML. An example of what I need to send:

<html> <head></head> <body> <form method="post" action="http://www. ... .com/login.jsp"> <textarea name="xml" wrap="off" cols="80" rows="30" spellcheck="false"> <loginInfo> <param name="username" type="string">USERNAME</param> <param name="pwd" type="string">PASSWORD</param> </loginInfo> </textarea> <input type="hidden" name="Login" value="1"/> <input type="submit" name="go" value="go" /> </form> </body> </html> 

An example of what I get (XML):

 <UserPluginInfo> <PluginInfo> <param name="pluginUid" type="string">1</param> </PluginInfo> <UserInfo> <param name="username" type="string">USERNAME</param> </UserInfo> </UserPluginInfo> 

I found a Robert Raguet-Schofield blog written in 2009 about interacting with Twitter that uses J / Link to access Java to perform HTTP POST and process the response.

My question is, is this the best method to accomplish my task or has Mathematica been developing since 2009, and is there a better (more direct) way to accomplish my task?

+42
wolfram-mathematica webserver
Dec 02 2018-11-12T00:
source share
1 answer

Although this may not be the best way, an alternative approach to circumvent the need for J / Link would be to create an intermediate CGI script to translate the request from GET to POST for you.

This script file will be hosted on an accessible server, it will execute the given GET request, make a POST request on the target page, and then output / return the XML result in the usual way.

For example, using curl in PHP, which will work well - although, obviously, you could achieve the same functionality in almost any CGI language.

 <?php $c = curl_init(); // set the various options, Url, POST,etc curl_setopt($c, CURLOPT_URL, "http://www. ... .com/login.jsp"); // Target page curl_setopt($c, CURLOPT_HEADER, false); curl_setopt($c, CURLOPT_POST, true); curl_setopt($c, CURLOPT_RETURNTRANSFER, false); // POST the incomming query to the Target Page curl_setopt($c, CURLOPT_POSTFIELDS, $_SERVER['QUERY_STRING']); curl_exec($c); curl_close($c); // Output the XML response using header/echo/etc... // You might need to also send some of the POST request response headers // use CURLOPT_HEADER to access these... ?> 

From the point of view of Mathmatica, this is much simpler, because you simply use the built-in import method to create a standard GET request on the proxy page, but get the XML result from the POST request on the login page.

+1
Feb 21 '12 at 15:00
source



All Articles