2016-02-23 17 views
0

我試圖做一個頁面的帖子,所以不必完成表單,但似乎無法得到它的工作。從頁面表單獲取POST URL,我錯過了什麼?

形式是在這裏:

http://www.tuffnells.co.uk/proof-of-delivery

我想要做的事:

echo file_get_contents("http://www.tuffnells.co.uk/proof-of-delivery?ctl00_maincontent_ctl02_btnDoPODLookup=true&ctl00$maincontent$ctl02$tbAccountRef=01484267&ctl00$maincontent$ctl02$tbConsignmentRef=2837&ctl00$maincontent$ctl02$tbDestPostcode=AL15BY"); 

ctl00 $ $搜索Maincontent $ ctl02 = tbAccountRef 01484267 ctl00 $ $搜索Maincontent $ ctl02 tbConsignmentRef = 2837 ctl00 $ maincontent $ ctl02 $ tbDestPostcode = AL15BY

這些是我通過的3個,但也許我錯過了URL中的其他內容,這就是爲什麼它不工作,我不確定是否有人可以從表單中看到我可能會丟失的東西。

**,捲曲修訂版**

<base href="http://www.tuffnells.co.uk"/> 

<?php 

if (isset($_GET['orderid'])){ 
    $url = 'http://www.tuffnells.co.uk/PODLookupResults.aspx?__EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATEGUID=7ca82b1d-b722-4cdc-b74a-b338d8577ffa&__VIEWSTATE=&__EVENTVALIDATION=%2FwEdAAevVXD1oYELeveMr0vHCmYPaomE%2FDwQD43eOdzEj3p%2Fm4U4pgxq6tlupSJfQZQBazFFj%2F1LmlGLyHFagz1yHZm8bjowVgAJ8C3e%2B2bVMPt91KjXCHjnAsonQDi2zFSuasUVzpitHiLDCDtiLHCjNCQG4CxrbV5VPFqBeOgs2X52AD%2FEb%2BYR%2BEJ68PaN2CiyKzE%3D&ctl00%24ctl16%24tbHeaderSearch=Search..&ctl00%24maincontent%24tbAccountRef=01484267&ctl00%24maincontent%24btnDoPODLookup=Search+Again'; 
    $fields = array(
     'ctl00%24maincontent%24tbConsignmentRef' => urlencode($_POST['orderid']), 
     'ctl00%24maincontent%24tbDestPostcode' => urlencode($_GET['postcode']) 
    ); 

    //url-ify the data for the POST 
    foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; } 
    rtrim($fields_string, '&'); 

    //open connection 
    $ch = curl_init(); 

    //set the url, number of POST vars, POST data 
    curl_setopt($ch,CURLOPT_URL, $url); 
    curl_setopt($ch,CURLOPT_POST, count($fields)); 
    curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string); 

    //execute post 
    $result = curl_exec($ch); 

    //close connection 
    curl_close($ch); 
} 

?> 

http://ambientlounge.com/external/ukTracking.php?orderid=2837&postcode=AL15BY

+4

'的file_get_contents()'不* *後什麼。你需要看看cURL之類的東西。 –

+0

好吧,新的PHP所以不知道如何,但如果你去這裏:http://www.tuffnells.co.uk/proof-of-delivery?ctl00_maincontent_ctl02_btnDoPODLookup=true & ctl00 $ maincontent $ ctl02 $ tbAccountRef = 01484267 & ctl00 $ maincontent $ ctl02 $ tbConsignmentRef = 2837 & ctl00 $ maincontent $ ctl02 $ tbDestPostcode = AL15BY它不起作用...所以猜想需要找出正確的url來發布? – James

+0

URL不接受查詢字符串,所以添加查詢字符串將永遠不會工作。你必須學習像[cURL](http://php.net/manual/en/book.curl.php) –

回答

0

你需要使用curl做出後是這樣的。 例如:

$curl = curl_init(); 
     $options = array(
     CURLOPT_RETURNTRANSFER => 1, 
     CURLOPT_URL => 'http://www.tuffnells.co.uk/proof-of-d...');//etc 
     curl_setopt_array($curl,$options); 
     echo $options[CURLOPT_URL]; //will print you all the path- just for testing. 
     curl_exec($curl); 
     curl_close($curl); 

希望它可以幫助...

+0

我試過這個:http://ambientlounge.com/external/ukTracking.php?orderid=2837&postcode=AL15BY - 它傳遞給URL,但我怎麼能返回網站的內容,因爲我需要然後推送到Ajax/jQuery並使用我需要從頁面的div。那可能嗎? – James

+0

你是什麼意思:「返回網站的內容,因爲我需要然後推送到ajax/jquery」你發送它...你想發送它後使用這個內容? –

+0

我在另一個網站上有一個html頁面,我將通過orderid和postcode從ajax調用該php curl文件,以便從tuffuneel網站抓取頁面內容,這是跟蹤信息,然後想要返回它,所以我可以顯示在外部如果這是有道理的頁面。 – James

相關問題