好吧,首先,我必須缺少一些東西,所以我很抱歉,可能會成爲一個新問題...爲什麼我會從瀏覽器地址欄調用中的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'];
?>
我想你還沒有配置'file_get_contents'在php.ini文件中設置。確保配置與否。 –
'$ DestURL'是否有https? – Salman
感謝@薩爾曼的想法,可悲的是 - 這是我必須做觸發器/響應方法的原因,因爲響應結果會觸發計費操作,所以我基本上正在做一個滾動密鑰的手動版本以確保嘗試並欺騙整個負載更難... –