客户端发请求头后跟着一个xml信息,怎么才能解析呢,哪位给举个例子,谢了

解决方案 »

  1.   


    $strXML = $_POST['xxx'];
    //$strXML = $_GET['xxx'];
    $xml = simplexml_load_string($strXML);
    var_dump($xml);
      

  2.   

    php的手册呀.
    官网去下
    <?php
    $xml = new SimpleXMLElement(
    '<person>
     <child role="son">
      <child role="daughter"/>
     </child>
     <child role="daughter">
      <child role="son">
       <child role="son"/>
      </child>
     </child>
    </person>');foreach ($xml->children() as $second_gen) {
        echo ' The person begot a ' . $second_gen['role'];    foreach ($second_gen->children() as $third_gen) {
            echo ' who begot a ' . $third_gen['role'] . ';';        foreach ($third_gen->children() as $fourth_gen) {
                echo ' and that ' . $third_gen['role'] .
                    ' begot a ' . $fourth_gen['role'];
            }
        }
    }
    ?> 
      

  3.   

    通过抓包看,客户端发来的httpheader,然后后面就是xml。像这样:
    POST /cm/portalapi HTTP/1.1Host: 111.140.17.43:28080Cookie: JSESSIONID=C3E17C85AED6C57B658CC7F27AE68BBD; Path=/cmreadContent-Length: 178Content-Type: application/xmlClient-Agent: s60_v3_v1r2_0030/240*320x-up-calling-line-id: 13888888888user-id: a15ba9b5458ec3e3caa8909d84113674APIVersion: 1.0.0Action: addUserBookClientHash: 0sEicJNzReY/EU8dxXpBgA==<Request><AddUserBookReq><Book><contentID>92357</contentID><chapterID>92366</chapterID><position>37</position></Book></AddUserBookReq></Request>我怎么首先获取这个xml呢,
      

  4.   

    $strXML = file_get_contents("php://input");
      

  5.   

    你没明白我的意思,我没有现成的xml文件啊
    就是客户端发过来,我怎么获得这个xml文件,再进行解析。就像我用$_GET['xxx']可以获得get后面的参数。
    现在问题是我怎么获得这个xml文件先。
    刚学,不太懂,麻烦了
      

  6.   

    楼上的我帖的代码就是获取XML的代码,
    因为你客户端POST数据,是直接POST的,没有键值,所以只能这样获取.
    你试试就知道了.
      

  7.   

    哈哈,你可以用 file_get_contents()  或者 curl_init()
      

  8.   

    铁公鸡的没错
    $strXML = file_get_contents("php://input");
    得到的时XML文件的内容。
    对$strXML进行XML解析就行了。XML解析的资料网上搜一下,一堆
      

  9.   


    php://input allows you to read raw POST data. It is a less memory intensive alternative to $HTTP_RAW_POST_DATA and does not need any special php.ini directives. php://input is not available with enctype="multipart/form-data". 
      

  10.   


    [code=PHP]
    $doc = new DOMDocument();
    $doc->loadXML(‘<person>
     <child role="son">
      <child role="daughter"/>
     </child>
     <child role="daughter">
      <child role="son">
       <child role="son"/>
      </child>
     </child>
    </person>’);//loadXML($result)
    $CRS = $doc->documentElement; 
    $Item = $CRS->getElementsByTagName(person);
    [/code]
      

  11.   

    问题是我太懂啊,$strXML=file_get_contents("php://input"); 直接输这个就能把post的信息获过来啊