Error fetching http headers in SoapClient

前端 未结 15 1006
抹茶落季
抹茶落季 2020-12-08 18:50

I\'m trying to invoke a WS over https on a remote host:remote port and I get:

Error fetching http headers

using the PHP5 SoapCli

相关标签:
15条回答
  • 2020-12-08 19:06

    I just wanted to add, for completeness sake, that similar to Manachi I received this message because the client certificate I was using required a passphrase and I accidentally had an extra character at the end of the passphrase. This post is just to offer up another suggestion for what to look into. If the host requires the use of a client certificate (via local_cert parameter) make sure you provide the correct path to the cert and the correct passphrase (if one is needed). If you don't, it is very likely you will see this same error message.

    0 讨论(0)
  • 2020-12-08 19:09

    We encountered Error fetching http headers on every second call of SoapClient::__soapCall(,). However, not every soap endpoint/soap server was affected.

    It turned out that switching to http was working reliably for all servers, but connections via https/secure HTTP showed above symptoms. The openssl_error_string() as suggested by Furgas did not return any errors.

    It turned out that the misbehaving soap servers sent a HTTP-header with every response which lead to the soap client choking on the second soap call: Connection: Upgrade, close. The well-behaving servers did not send a Upgrade on successive responses.

    What worked for us:

    • setting keep_alive to false, as mentioned by Thiago
    • unsetting the Upgrade- and Connection-headers via .htaccess files

    Although the well-behaving soap servers did not need any of this, the misbehaving once needed both the keep_alive set to false and the unsetting of the headers.

    # .htaccess
    Header unset Upgrade
    Header unset Connection
    

    The root-cause is still unclear, but there is a bug report at Apache regarding Upgrade headers when using HTTPS.

    0 讨论(0)
  • 2020-12-08 19:12

    I suppose it's too late, but I have the same problem. I try the socket timeout but it doesn't work. My problem was that the client and the server where in the same physical server. With the client code working in the same physical server , I get this error, but, with the same client code moved to my localhost, requesting the server, (client and server was executed in two differents mechines) all works fine.

    Maybe that can help someone else!

    0 讨论(0)
  • 2020-12-08 19:13

    Just wanted to share the solution to this problem in my specific situation (I had identical symptoms). In my scenario it turned out to be that the ssl certificate provided by the web service was no longer trusted. It actually turned out to be due to a new firewall that the client had installed which was interfering with the SOAP request, but the end result was that the certificate was not being correctly served/trusted.

    It was a bit difficult to track down because the SoapClient call (even with trace=1) doesn't give very helpful feedback.

    I was able to prove the untrusted certificate by using:

    openssl s_client -connect <web service host>:<port>
    

    I know this won't be the answer to everyone's problem, but hopefully it helps someone. Either way I think it's important to realise that the cause of this error (faultcode: "HTTP" faultstring: "Error Fetching http headers") is usually going to be a network/socket/protocol/communication issue rather than simply "not allowing enough time for the request". I can't imagine expanding the default_socket_timeout value is going to resolve this problem very often, and even if it does, surely it would be better to resolve the issue of WHY it is so slow in the first place.

    0 讨论(0)
  • 2020-12-08 19:14

    Please check for the response HTTP-Header. In my case, the following header was set on the API-Site:

    <IfModule mod_headers.c>
        Header set Connection keep-alive
    </IfModule>
    

    It seems like the PHP SoapClient can't deal with that option. As a result, the response body was empty, but content-length in the response-header has been set correctly.

    Remove that line or change it to "close" solved my issue.

    0 讨论(0)
  • 2020-12-08 19:16

    I had the same issue and tried the following by disabling keep_alive.

    $api_proxy = new SoapClient($api_url, array('trace' => true, 'keep_alive' => false));
    

    However, that didn't work for me. What worked worked for me was disabling the SOAP cache. It appears to have been caching the wrong requests and after disabling I actually noticed my requests were executing faster.

    On a linux server you can find this in your /etc/php.ini file.

    Look for soap.wsdl_cache_enabled=1 and change it to soap.wsdl_cache_enabled=0.

    Don't forget to reload apache. service httpd reload

    0 讨论(0)
提交回复
热议问题