Jquery inside PHP class


Jquery inside PHP class

我需要通过php将一些XML发布到我们网络上的API。通常我会用Curl来做这件事,我知道它工作得很好,但是我的脚本运行的服务器没有Curl,如果不深入所有的细节,它就不能安装,因为它会破坏服务器上其他一些重要的生产应用程序。

经过一番思考,我希望通过jquery将我的XML发布到API。我想知道是否有人知道是否可以从PHP类中访问jquery ?我知道这听起来很疯狂,我肯定有人会告诉我为什么我不应该这样做,但对我来说,这听起来是个合理的解决方案。

否则,我可能不得不遍历类并尝试将xml拉回使用该类发送xml的控制器和页面。

p。S我们已经尝试命令行curl来解决我们的问题,它确实有效,但是我们在一些请求中遇到URL长度的问题,因为XML可能非常大,太长而无法通过URL传递。

任何想法吗?

请使用套接字。

复制自@Val张贴的链接:

<?php
$fp = fsockopen("www.example.com", 80, $errno, $errstr, 30);
if (!$fp)
{
echo 'Could not open connection.';
}
else
{
$xmlpacket ='<?XML version="1.0"?>
<Your_XML>
</Your_XML>';
$contentlength = strlen($xmlpacket);
$out = "POST /script_name.php HTTP/1.0'r'n";
$out .= "Host: www.example.com'r'n";
$out .= "Connection: Keep-Alive'r'n";
$out .= "Content-type: application/x-www-form-urlencoded'r'n";
$out .= "Content-length: $contentlength'r'n'r'n";
$out .= "XML=$xmlpacket";
fwrite($fp, $out);
while (!feof($fp))
{
$theOutput .= fgets($fp, 128);
}
fclose($fp);
// $theOutput is the response returned from the remote script
}
?>

你不能。jQuery在客户端的浏览器中运行,而不是在服务器上。您可以将Javascript发送到客户端并在那里进行操作。但是使用file_put_contents,您也可以将数据发送到另一端,如果它接受每个GET。