Wolfram mathematica Mathematica 8.0使用HTTP POST和XML与web服务器JSP交互

Wolfram mathematica Mathematica 8.0使用HTTP POST和XML与web服务器JSP交互,wolfram-mathematica,webserver,Wolfram Mathematica,Webserver,我的任务是使用Mathematica通过JSP使用HTTP POST和XML与第三方的web服务器交互。我需要发送的内容示例: <html> <head></head> <body> <form method="post" action="http://www. ... .com/login.jsp"> <textarea name="xml" wrap="off" cols="80" rows="30" spellcheck="

我的任务是使用Mathematica通过JSP使用HTTP POST和XML与第三方的web服务器交互。我需要发送的内容示例:

<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>

用户名
密码
我将收到的示例(XML):


1.
用户名
我在2009年发现了一篇关于与Twitter交互的文章,它使用J/Link访问Java来执行httppost并处理响应


我的问题是,这是完成我任务的最佳方法,还是Mathematica自2009年以来一直在发展,并且有更好的方法(更直接)来完成我的任务?

虽然这可能不是更好的方法,绕过J/Link需求的另一种方法是设置一个中间CGI脚本,为您将请求从
GET
转换为
POST

此脚本文件将位于可访问的服务器上,它将接受指定的GET查询,在目标页面上发出POST请求,然后以正常方式输出/返回结果XML

例如,在PHP中使用
curl
,这将很好地工作——尽管很明显,在几乎任何CGI语言中都可以实现相同的功能

<?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...

?>


从Mathmatica的角度来看,这要简单得多,因为您只需使用内置的
import
方法在代理页面上发出标准的
GET
请求,但从登录页面上的
POST
请求中获取结果XML。

Ragfield还回答了POST上的一个问题:在这里还可以找到一些POST内容问题:根据对的评论,我认为您必须坚持使用
JLink
<?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...

?>