简体   繁体   English

如何修复Laravel 5.7中的Error SimpleXMLElement?

[英]How to fix Error SimpleXMLElement in Laravel 5.7?

Problem: 问题:

I want to create XML format like function below, but when I run it in postman, I get the below error: 我想创建类似下面函数的XML格式,但是当我在邮递员中运行它时,出现以下错误:

Exception: String could not be parsed as XML. 例外:字符串无法解析为XML。

How to fix this? 如何解决这个问题?

Script: 脚本:

This is my function: 这是我的功能:

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();
}

$xmlstr is not a valid xml . $xmlstr不是有效的xml You can try to validate it in 您可以尝试在中进行验证

http://xmlbeautifier.com/ http://xmlbeautifier.com/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM