2011-01-25 75 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