douquanhui5735 2014-10-08 07:39
浏览 41

从XML站点获取数据

I want to get some data from a site based on xml's.
The problem is I need to be logged to it as a PublicUser without password.

I have tryed:

$url = 'http://IP/wcd/system_counter.xml';
$content = file_get_contents($url);
echo $content

But i only get this:

err En ReloginAttempt /wcd/index.html false

This is the xml code used for loggin:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="top.xsl" type="text/xsl"?>
<MFP>
<SelNo>Auto</SelNo>
<LangNo>En</LangNo>
<Service><Setting><AuthSetting><AuthMode><AuthType>None</AuthType>
<ListOn>false</ListOn>
<PublicUser>true</PublicUser>
<BoxAdmin>false</BoxAdmin>
</AuthMode><TrackMode><TrackType>None</TrackType></TrackMode></AuthSetting>
<MiddleServerSetting><ControlList><ArraySize>0</ArraySize></ControlList><Screen>
<Id>0</Id></Screen></MiddleServerSetting>
</Setting></Service><LangDummy>false</LangDummy></MFP>

Is there a way to send the user as well when i want to get the XML info ?

  • 写回答

1条回答 默认 最新

  • dongshendi3599 2014-10-08 08:50
    关注

    You cannot access pages requiring posted login information using file_get_contents. Instead you need to use curl. Something along these lines:

    $ch = curl_init($url); // The url you want to call
    
    curl_setopt_array(
        $ch, array(
            CURLOPT_RETURNTRANSFER => 1,
            CURLOPT_POST           => 1,
            CURLOPT_POSTFIELDS     => $login_xml, // The xml login in string form
        )
    );
    
    //getting response from server
    $response = curl_exec($ch);
    
    echo curl_error($ch);
    curl_close($ch);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程