How to write a SOAP request over HTTPS

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Stwange
    Recognized Expert New Member
    • Aug 2007
    • 126

    How to write a SOAP request over HTTPS

    Hi,

    As part of some work I'm doing I need to send a SOAP request of an xml file ($xml) to https://login.live.com/RST.srf

    I have no idea how to do this and I was hoping someone could point me in the right direction.
    I've tried:
    Code:
    $client = new SoapClient("https://login.live.com/RST.srf");
    $funcs = $client->__getFunctions();
    print_r($funcs);
    to dump a list of functions, but it gives me:
    Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't find <definitions> in 'https://login.live.com/RST.srf'

    I've looked at SoapClient->__doRequest( ) but it seems to have too many arguments.

    Any help would be seriously appreciated,

    Thank-you.
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Heya, Stwange.

    It looks like your SOAP client is successfully connecting, but it's not finding a properly-formatted WSDL flie.

    SOAP generally requires a .wsdl file, not a .srf; see if there's a .wsdl file you can request instead.

    Comment

    • Stwange
      Recognized Expert New Member
      • Aug 2007
      • 126

      #3
      Originally posted by pbmods
      Heya, Stwange.

      It looks like your SOAP client is successfully connecting, but it's not finding a properly-formatted WSDL flie.

      SOAP generally requires a .wsdl file, not a .srf; see if there's a .wsdl file you can request instead.
      Hi,

      Thanks for your response. I read some of the SOAP methods connect to non-wsdl files, and don't require a function name but I still can't find any such implementations in PHP.

      I did find a way around this though by using a HTTP POST instead, I'll post the solution just in case anyone else needs a workaround:
      Code:
      /* $xml is defined elsewhere as the XML document I want to send */
      $tokenURL = fsockopen('ssl://login.live.com', 443);
      $http =  "POST /RST.srf HTTP/1.1\r\n";
      $http .= "Accept: */*\r\n";
      $http .= "User-Agent: MSMSGS\r\n"; /* I'm writing for an MSN bot */
      $http .= "Host: login.live.com\r\n";
      $http .= "Content-Length: " . strlen($xml) . "\r\n";
      $http .= "Connection: Keep-Alive\r\n";
      $http .= "Cache-Control: no-cache\r\n\r\n";
      fputs($tokenURL, $http . $xml);
      That will send the SOAP request to the server. To retrieve the servers response you can just use fgets($tokenURL , 1024) - the last string may give you an SSL fatal error if the socket has been closed (ie. if the server sends the last string and disconnects), so use @fgets to hide it after testing.

      If you get an XML file back from the server that says 'Invalid Request', these are the three things I found were causing that:
      1. Some of my strings were in single quotes instead of double, meaning the \r\n was being sent as text.
      2. The XML input file had excessive whitespace, ie. <someTag> value </someTag> - outside of tags it doesn't really matter but I removed it all using a replace on '>\s+' and '\s+<' to '>' and '<' respectively.
      3. Make sure the XML input ends in \r\n\r\n (and again make sure you use double quotes here).
      I hope this saves someone else at least a fraction of the time I've spent on it.

      Comment

      Working...