OK, firstly, I must be missing something, so I apologise for what may turn out to be a newb question...
好的,首先,我必须遗漏一些东西,所以我为可能会成为一个新问题道歉...
I have a complicated bit of code that is just not working, so am putting it out here or any pointers. I can't share too much as it is proprietary, so here goes.
我有一些复杂的代码,只是没有用,所以我把它放在这里或任何指针。我不能分享太多,因为它是专有的,所以这里。
I have three tiers: User, server, appliance. The server, and appliance are php enabled, the client is either IE, or Chrome - the behavior is the same.
我有三层:用户,服务器,设备。服务器和设备启用了php,客户端是IE或Chrome - 行为是相同的。
The user tier sends data from an HTML 5 form to the server, which in turn logs it in a database, and can send to the appliance - all OK here.
用户层将数据从HTML 5表单发送到服务器,然后服务器将其记录在数据库中,并可以发送到设备 - 所有这些都可以。
Due to the appliance not being https enabled I am trying to set up a trigger/response model. This means sending an abbreviated message, or key (as a GUID), to the appliance, and then the appliance calling back to the server for an XML message for processing. The call back is done using a get_file_contents()
call.
由于设备未启用https,我尝试设置触发/响应模型。这意味着向设备发送缩写消息或密钥(作为GUID),然后设备回调服务器以获取XML消息进行处理。回调是使用get_file_contents()调用完成的。
All the parts seem to be working, the server response is retrieving the XML and the client is picking the XML headers correctly - however when the appliance is performing the call, the response is empty.
所有部分似乎都在工作,服务器响应正在检索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";
?>
Any ideas from anyone greatly appreciated.
任何人的想法都非常感谢。
The Server Web service reads like this:
Server 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'];
?>
1 个解决方案
#1
0
I still have no real reason why this is happening, however a related post helped over here: PHP ini file_get_contents external url helped a huge amount - Thanks to both responses.
我仍然没有真正的理由为什么会发生这种情况,但是相关帖子在这里得到了帮助:PHP ini file_get_contents外部网址帮助了很多 - 感谢两个回复。
I've changed the get from using file_get_contents() to a CURL call. Problem Solved.
我已经将使用file_get_contents()的get更改为CURL调用。问题解决了。
Here is the code:
这是代码:
function get_message($URL)
{
/*
* This code has been lifted from *: 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;
}
#1
0
I still have no real reason why this is happening, however a related post helped over here: PHP ini file_get_contents external url helped a huge amount - Thanks to both responses.
我仍然没有真正的理由为什么会发生这种情况,但是相关帖子在这里得到了帮助:PHP ini file_get_contents外部网址帮助了很多 - 感谢两个回复。
I've changed the get from using file_get_contents() to a CURL call. Problem Solved.
我已经将使用file_get_contents()的get更改为CURL调用。问题解决了。
Here is the code:
这是代码:
function get_message($URL)
{
/*
* This code has been lifted from *: 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;
}