Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

looks like we got no XML document #180

Closed
tobby opened this issue Oct 18, 2019 · 8 comments
Closed

looks like we got no XML document #180

tobby opened this issue Oct 18, 2019 · 8 comments

Comments

@tobby
Copy link

tobby commented Oct 18, 2019

looks like we got no XML document [/.../vendor/garethp/php-ews/src/API/NTLMSoapClient.php:118]

@reeperbahnause
Copy link

I'm getting the same message.
I think it has something to do with blocked contents but I'm not sure about that.

image

I will try to figure out whats going on and let you know.

@reeperbahnause
Copy link

I was wrong. It has nothing to do with blocked contents.
The email body I try to fetch, has an invalid xml character 
This is why the response can not be parsed.
I will try to figure out how to solve this problem.

@reeperbahnause
Copy link

reeperbahnause commented Jun 19, 2020

Quick fix for now is the following but for sure there are better ways to do it

File vendor/garethp/php-ews/src/API/NTLMSoapClient.php

    /**
     * Performs a SOAP request
     *
     * @link http://php.net/manual/en/function.soap-soapclient-dorequest.php
     *
     * @param string $request the xml soap request
     * @param string $location the url to request
     * @param string $action the soap action.
     * @param integer $version the soap version
     * @param integer $one_way
     * @return string the xml soap response.
     */
    public function __doRequest($request, $location, $action, $version, $one_way = 0)
    {
        $postOptions = array(
            'body' => $request,
            'headers' => array(
                'Connection' => 'Keep-Alive',
                'User-Agent' => 'PHP-SOAP-CURL',
                'Content-Type' => 'text/xml; charset=utf-8',
                'SOAPAction' => $action
            ),
            'verify' => $this->validate,
            'http_errors' => false
        );

        $postOptions = array_replace_recursive($postOptions, $this->auth);

        $response = $this->httpClient->post($location, $postOptions);

        $this->__last_request_headers = $postOptions['headers'];
        $this->_responseCode = $response->getStatusCode();

        //return $response->getBody()->__toString();

        $responseStr = $response->getBody()->__toString();
        $responseStr = str_replace('', '', $responseStr);
        return $responseStr;
    }

@reeperbahnause
Copy link

I did some more research and I have a working solution.
I found a solution using this StackOverflow answer:
https://stackoverflow.com/a/8092672/6708205

Here is the code of the working solution:

File vendor/garethp/php-ews/src/API/NTLMSoapClient.php

    /**
     * Performs a SOAP request
     *
     * @link http://php.net/manual/en/function.soap-soapclient-dorequest.php
     *
     * @param string $request the xml soap request
     * @param string $location the url to request
     * @param string $action the soap action.
     * @param integer $version the soap version
     * @param integer $one_way
     * @return string the xml soap response.
     */
    public function __doRequest($request, $location, $action, $version, $one_way = 0)
    {
        $postOptions = array(
            'body' => $request,
            'headers' => array(
                'Connection' => 'Keep-Alive',
                'User-Agent' => 'PHP-SOAP-CURL',
                'Content-Type' => 'text/xml; charset=utf-8',
                'SOAPAction' => $action
            ),
            'verify' => $this->validate,
            'http_errors' => false
        );

        $postOptions = array_replace_recursive($postOptions, $this->auth);

        $response = $this->httpClient->post($location, $postOptions);

        $this->__last_request_headers = $postOptions['headers'];
        $this->_responseCode = $response->getStatusCode();

        // ======================================================
        // MODIFICATION START
        // ======================================================
        //return $response->getBody()->__toString();

        $responseStr = $response->getBody()->__toString();
        libxml_use_internal_errors(true);
        $dom = new \DOMDocument("1.0", "UTF-8");
        $dom->strictErrorChecking = false;
        $dom->validateOnParse = false;
        $dom->recover = true;
        $dom->loadXML($responseStr);
        $xml = simplexml_import_dom($dom);
        libxml_clear_errors();
        libxml_use_internal_errors(false);

        return $xml->asXML();
        // ======================================================
        // MODIFICATION END
        // ======================================================
    }

@Garethp
Copy link
Owner

Garethp commented Jun 21, 2020

That passes my unit tests. Do you want to submit a pull request, or would you prefer I just commit under my name and release?

@reeperbahnause
Copy link

Just commit it under your name.
Thanks for your work!

@vytciv
Copy link

vytciv commented Jun 24, 2020

When we can expect this fix will be released? Cause I'm facing those invalid character issues quite for some time.

@Garethp
Copy link
Owner

Garethp commented Jun 24, 2020

This has been published as version 0.9.7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants