gpt4 book ai didi

php - 通过 PHP Curl 调用 SoapAction

转载 作者:行者123 更新时间:2023-12-05 08:00:21 25 4
gpt4 key购买 nike

我想通过 PHP 重新连接我的路由器。

控制台命令如下:

curl "http://192.168.178.1:49000/upnp/control/WANIPConn1" -H "Content-Type: text/xml; charset="utf-8"" -H "SoapAction: urn:schemas-upnp-org:service:WANIPConnection:1#ForceTermination" -d ""

我如何在 PHP 中使用 curl 来做到这一点?

最佳答案

$sPostfields ="<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\r\n"
."<s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">\r\n"
."<s:Body>\r\n"
."<u:ForceTermination xmlns:u=\"urn:schemas-upnp-org:service:WANIPConnection:1\" />\r\n"
."</s:Body>\r\n"
."</s:Envelope>\r\n";
$soap_do = curl_init();

$header = array(
"Content-Type: text/xml",
"Cache-Control: no-cache",
"Pragma: no-cache",
"SOAPAction: \"urn:schemas-upnp-org:service:WANIPConnection:1#ForceTermination\"",
"Content-length: ".strlen($sPostfields),
);

curl_setopt($soap_do, CURLOPT_URL, "http://192.168.178.1:49000/upnp/control/WANIPConn1" );
curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true );
curl_setopt($soap_do, CURLOPT_POST, true );
curl_setopt($soap_do, CURLOPT_POSTFIELDS, $sPostfields);
curl_setopt($soap_do, CURLOPT_HTTPHEADER, $header );

$output = curl_exec($soap_do);
$aInfo = curl_getinfo($soap_do);
curl_close($soap_do);
print_r( $output );
print_r( $aInfo );
exit();

根据 OP @angelmedia 对问题的编辑。

关于php - 通过 PHP Curl 调用 SoapAction,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18327843/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com