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

Whilst this may not be a better way, an alternative approach to circumvent the need of J/Link would be to set up an intermediate CGI script to translate the request from GET to POST for you.

This script file would sit on an accessible server, it would take the specified GET query, make a POST request on the target page, then output/return the result XML in the normal way.

For example, using curl in PHP that would work well – although obviously it would be possible to achieve the same functionality in pretty much 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 Mathmatica stand point this is much simpler as you simply use the built in import method to make a standard GET request on the proxy page but get the result XML from a POST request on the login page.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)