Error fetching http headers in SoapClient

前端 未结 15 1008
抹茶落季
抹茶落季 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:20

    This error is often seen when the default_socket_timeout value is exceeded for the SOAP response. (See this link.)

    Note from the SoapClient constructor: the connection_timeout option is used for defining a timeout value for connecting to the service, not for the timeout for its response.

    You can increase it like so:

    ini_set('default_socket_timeout', 600); // or whatever new value you want
    

    This should tell you if the timeout is the issue, or whether you have a different problem. Bear in mind that you should not use this as a permanent solution, but rather to see if it gets rid of the error before moving on to investigate why the SOAP service is responding so slowly. If the service is consistently this slow, you may have to consider offline/batch processing.

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

    I got this same error and in my case the server I was sending the request to was replying with a 504 Gateway Time-out error. I didn't realize this until I went to the URL in a browser that was being requested by the SOAP request:

    eg. https://soap-request-domain-here.com/path/to/file.wsdl

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

    I had this problem and I checked, and in my case, was the Firewall. The PHP not show the error correctly. To perform the request, the Firewall answered:

    HTTP/1.1 200 OK
    Content-Type: text/html; charset=utf-8
    ...
    <html
    ...
    <h1>Direct Access IP is not allowed</h1>
    ...
    </html>
    

    The SoapClient expects the SOAP envelope but receives a HTML code. That's why PHP responds with: "Error Fetching Http Headers" because it can not understand what he received in response. To resolve the problem, contact your network administrator to verify if there is any Firewall, NAT or proxy getting in the way and then ask them to make the necessary arrangements.

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

    In recent releases from Zend SOAP client not having "connection_timeout" and "Keep_alive" parameters at all.

    You can see the piece of code I have attached as an image. The only way to solve this issue to increase your default socket timeout in php.ini

    default_socket_timeout = 1000
    

    I hope it will solve your issue. Give an upvote if it works.

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

    I faced same problem and tried all the above solutions. Sadly nothing worked.

    1. Socket Timeout (Didn't work)
    2. User Agent (Didn't work)
    3. SoapClient configuration, cache_wsdl and Keep-Alive etc...

    I solved my problem with adding the compression header property. This is actually required when you are expecting a response in gzip compressed format.

    //set the Headers of Soap Client. 
    $client = new SoapClient($wsdlUrl, array(
        'trace' => true, 
        'keep_alive' => true,
        'connection_timeout' => 5000,
        'cache_wsdl' => WSDL_CACHE_NONE,
        'compression'   => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP | SOAP_COMPRESSION_DEFLATE,
    ));
    

    Hope it helps.

    Good luck.

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

    None of the above techniques worked for me.

    When I analyzed the request header from __getLastRequestHeaders, I saw the following:

    POST /index.php/api/index/index/?SID=012345 HTTP/1.1 Host: www.XYZ.com

    The API URL I had been using was different, like www.ABC.com. I changed the API URL to www.XYZ.com/index.php/api?wsdl, and then it worked.

    Both URLs returned the same WSDL from the same server, but only one allowed login.

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