2011-01-25 78 views
0

我有一个窗体在我无法控制的服务器上。让我们称之为form1。我知道form1的POST要求。我正在创建自己的表单来向该表单提交数据1。让我们打电话给那个form2。 Form1会返回一个票号,我需要将该票号存储到一个部门数据库中,以及其他信息(这一点我很确定)。所以我需要form2(我的表单)将数据提交到form1(IT表单),并将form1的响应存储到我们的部门数据库中。提交表单商店响应

这样做最简单的方法是什么?我在网上搜索了几个小时,而且已经空了。我从JavaScript到iFrame到Ajax到jQuery。而我现在只是迷失了。

我的服务器是一个PHP服务器,他们是一个ASP服务器。

在此先感谢。

回答

0

这不是客户端操作,它是服务器端操作。不需要“form2”。您想为此使用curl。类似这样的:

// Set up a connection to the target of form1 (this is the "action" attribute of form1) 
$curl_connection = curl_init('http://hostname.com/form1.asp'); 

// Set up so options -- connection timout, store to string, follow redirects 
curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30); 
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1); 

// Set the post fields, this is just like a query string and contains the contents of form1 fields 
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, "field1=value1&field2=value2"); 

// Run the query and capture the results 
$data = curl_exec($curl_connection); 
curl_close($curl_connection); 

// At this point $data should contain the ticket number 
var_dump($data); 
+0

不幸的是,它必须是客户端操作。 “form1”服务器不会接受任何不协商NTLM身份验证的连接。所以我必须让它看起来像在互联网浏览器的用户提交表单。上面的解决方案是一个很棒的解决方案,但是我试过了:(服务器响应“未授权”,我尝试以明文形式发送密码,但它也不喜欢这样。 – 2011-01-27 06:05:57