Pomoc - Szukaj - U¿ytkownicy - Kalendarz
Pe³na wersja: Mydlane PHP
Forum PHP.pl > Forum > PHP
tnkywe
Witam,
Probowalem stworzyc skrypt wykorzystujacy cURL'a oraz SOAP do laczenia sie z serwisem Google (z wykorzystaniem ich API).
Oto co stworzylem (odrazu mowie ze nie znam sie ani SOAP, mistrzem w php tez nie jestem):

  1. <?php
  2. $url='http://api.google.com/search/beta2';
  3. $host='api.google.com';
  4. $akcja='urn:GoogleSearchAction';
  5.  
  6. $request = '<'.'?xml version=\"1.0\" encoding=\"ISO-8859-1\"?'.'>
  7. <SOAP-ENV:Envelope SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:typens=\"urn:GoogleSearch\">
  8. <SOAP-ENV:Body>
  9. <typens:doGoogleSearch xmlns:typens=\"urn:GoogleSearch\">
  10. <key xsi:type=\"xsd:string\">XXXXXXXXXXXXXXXXXXXXXXXX</key>
  11. <q xsi:type=\"xsd:string\">asdasd</q>
  12. <start xsi:type=\"xsd:int\">0</start>
  13. <maxResults xsi:type=\"xsd:int\">10</maxResults>
  14. <filter xsi:type=\"xsd:boolean\">true</filter>
  15. <restrict xsi:type=\"xsd:string\"></restrict>
  16. <safeSearch xsi:type=\"xsd:boolean\">false</safeSearch>
  17. <lr xsi:type=\"xsd:string\"></lr>
  18. <ie xsi:type=\"xsd:string\">latin</ie>
  19. <oe xsi:type=\"xsd:string\">latin</oe>
  20. </typens:doGoogleSearch>
  21. </SOAP-ENV:Body>
  22. </SOAP-ENV:Envelope>';
  23.  
  24. $header[] = &#092;"Host: $host\";
  25. $header[] = &#092;"Accept: text/html;q=0.5, application/soap+xml\";
  26. $header[] = &#092;"Content-length: \".strlen($request);
  27. $header[] = &#092;"Connection: close\";
  28. $header[] = &#092;"SOAPAction: $akcjarn\";
  29. $header[] = $request;
  30.  
  31. $ch = curl_init();
  32. curl_setopt($ch, CURLOPT_CUSTOMREQUEST,'POST');
  33. curl_setopt($ch, CURLOPT_URL, $url);
  34. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  35.  
  36. curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); 
  37. curl_setopt($ch, CURLOPT_HEADER, 1); 
  38. $data=curl_exec($ch);
  39. curl_close($ch);
  40.  
  41. print('<h1>Wynik:</h1><pre>'.$data.'</pre>');
  42.  
  43. ?>


jako output dostaje:
  1. <h1>Wynik:</h1><pre>HTTP/1.1 500 Internal Server Error
  2. Content-Type: text/xml; charset=utf-8
  3. Cache-control: private
  4. Transfer-Encoding: chunked
  5. Date: Tue, 02 Aug 2005 18:39:17 GMT
  6. Server: GFE/1.3
  7. Connection: Close
  8.  
  9. <?xml version='1.0' encoding='UTF-8'?>
  10. <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:xsd="http://www.w3.org/1999/XMLSchema">
  11. <SOAP-ENV:Body>
  12. <SOAP-ENV:Fault>
  13. <faultcode>SOAP-ENV:Server.Exception:</faultcode>
  14. <faultstring>java.lang.NullPointerException</faultstring>
  15. <faultactor>/search/beta2</faultactor>
  16. </SOAP-ENV:Fault>
  17.  
  18. </SOAP-ENV:Body>
  19. </SOAP-ENV:Envelope>
  20. </pre>


Niezbyt rozumiem co zle zrobilem smile.gif
NuLL
Czy to temat na Pro - w±tpie

Pro -> php
tnkywe
Ok. Sorry chyba zle odczytalem to "pro" smile.gif Zagadnienie jest dosyc zaawansowane, myslalem ze na "pro" wiecej osob bedzie zorientowanych.
Tak czy siak probowal ktos napisac wlasna obsluge SOAPa w php ?
Wczesniej korzystalem z nusoap jednak tez byly problemy(akurat z przesylaniem naglowkow SOAP) sad.gif
To jest wersja lo-fi g³ównej zawarto¶ci. Aby zobaczyæ pe³n± wersjê z wiêksz± zawarto¶ci±, obrazkami i formatowaniem proszê kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.