通过PHP Curl调用SoapAction

通过PHP Curl调用SoapAction,php,soap,curl,Php,Soap,Curl,我想通过PHP重新连接我的路由器。 Console命令如下所示: 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实现这一点 提前谢谢 编辑

我想通过PHP重新连接我的路由器。 Console命令如下所示:

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();
$sPostfields=“\r\n”
.“\r\n”
.“\r\n”
.“\r\n”
.“\r\n”
.“\r\n”;
$soap\u do=curl\u init();
$header=数组(
“内容类型:text/xml”,
“缓存控制:无缓存”,
“Pragma:无缓存”,
“SOAPAction:\“urn:schemas upnp org:service:WANIPConnection:1#ForceTermination\”,
“内容长度:”.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\u exec($soap\u do);
$aInfo=curl\u getinfo($soap\u do);
卷曲关闭($soap\u-do);
打印(输出);
印刷费($aInfo);
退出();

如果只在PHP中使用SOAP函数,而不使用CURL,则会简单得多。实际上,自2010年以来,SOAP扩展不受支持,还有其他客户端: