【问题标题】:How to fix Error SimpleXMLElement in Laravel 5.7?如何修复 Laravel 5.7 中的错误 SimpleXMLElement?
【发布时间】:2019-03-06 07:27:16
【问题描述】:

问题:

我想创建类似下面函数的 XML 格式,但是当我在邮递员中运行它时,我收到以下错误:

异常:无法将字符串解析为 XML。

如何解决这个问题?

脚本:

这是我的功能:

public function testapi(Request $request){
    $url = "http://xxx.xx.x.xx:xxxx/xxxx/Activity?wsdl";
    $client = new \nusoap_client($url, 'wsdl');

    $xmlstr = '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:c1f="http://splwg.com/C1FieldActivityMaintenance.xsd">';

    $xml = new \SimpleXMLElement($xmlstr); 

    $header = $xml->addChild('Header');         
    $security = $header->addChild('wsse:Security', '', 'wsse');         
    $userToken = $security->addChild('wsse:UsernameToken');             
    $userToken->addChild('wsse:Username', env('Username', ''));           
    $userToken->addChild('wsse:Password', env('Password', ''));               


    $client = new Client();   
    $response = $client->post($url, [         
                    'headers' => [            
                        'SOAPAction' => $action,      
                        'Content-Type' => 'text/xml'          
                        ],          
                    'body' => $xml   
                ]);  

    return $response->getBody()->getContents();
}

【问题讨论】:

    标签: php laravel-5 soapui


    【解决方案1】:

    $xmlstr 不是有效的xml。您可以尝试在

    中验证它

    http://xmlbeautifier.com/

    【讨论】:

    • 我试过了,但它不起作用,我遇到了同样的错误
    • 你确定你有正确的 xml,因为那在我看来不像 xml?
    猜你喜欢
    • 2019-10-17
    • 2019-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-10
    • 2020-01-14
    • 2019-09-20
    相关资源
    最近更新 更多