2013-08-05 27 views
1

好吧,首先,我必須缺少一些東西,所以我很抱歉,可能會成爲一個新問題...爲什麼我會從瀏覽器地址欄調用中的PHP WEB服務獲得空的返回值?

我有一個複雜的代碼只是不工作,所以我把它出來這裏或任何指針。我不能分享太多,因爲它是專有的,所以在這裏。

我有三層:用戶,服務器,設備。服務器和設備都啓用了php,客戶端是IE或Chrome - 行爲是相同的。

用戶層將數據從HTML 5表單發送到服務器,然後服務器將其記錄到數據庫中,然後發送到設備 - 這裏都可以。

由於設備未啓用https,因此我嘗試設置觸發器/響應模型。這意味着將簡短消息或密鑰(作爲GUID)發送到設備,然後設備將回調到服務器以處理XML消息。回撥是使用get_file_contents()呼叫完成的。

所有部分似乎都在工作,服務器響應正在檢索XML,客戶端正在正確選取XML標頭 - 但是,當設備執行調用時,響應爲空。

$result = file_get_contents($DestURL) ; 
// If I call the value in $DestURL in a browser address 
// box - it all works 
// If I echo the $result, it is empty, and then nothing 
// executes, except the last line. 
if (strlen($result)== 0) { 
    // ==> this is not executing <== 
    $msg = "Failed to open the <a href='" . htmlspecialchars($DestURL) . "'> URL<a>: " . htmlspecialchars($DestURL); 
    $result="Error"; 
} 
// ==> this is not executing <<== 
if ($result=="Error") 
    { 
    /* 
    * need to send an error message 
    */ 
    } 
else 
    { 
    $result = PrintMessage($my_address, $result 
    } 
// ==> This is executing <== 
Echo "all Finished"; 
?> 

任何人的任何想法非常讚賞。

服務器Web服務的內容是這樣的:

<?php 
    header("Content-type: text/xml"); 
    // a bunch of items getting the data from the database 
    $result = mysqli_query($con, $sql); 
    $row = mysqli_fetch_array($result); 
    echo $row['message_XML']; 
?> 
+0

我想你還沒有配置'file_get_contents'在php.ini文件中設置。確保配置與否。 –

+0

'$ DestURL'是否有https? – Salman

+0

感謝@薩爾曼的想法,可悲的是 - 這是我必須做觸發器/響應方法的原因,因爲響應結果會觸發計費操作,所以我基本上正在做一個滾動密鑰的手動版本以確保嘗試並欺騙整個負載更難... –

回答

0

我還有爲什麼發生這種情況沒有真正的理由,然而,相關的帖子幫助在這裏: PHP ini file_get_contents external url幫助一個巨大的數額 - 由於兩種反應。

我已經改變了從使用file_get_contents()獲得的CURL調用。問題解決了。

下面是代碼:

function get_message($URL) 
{ 
    /* 
    * This code has been lifted from stackoverflow: URL to the article 
    */ 
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_URL, $URL); 
    // Can also link in security bits here. 
    $data = curl_exec($ch); 
    curl_close($ch); 
    return $data; 
} 
+0

添加到您的原始問題(使用編輯鏈接) - 這不是一個答案! –

相關問題