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):
<?php $url='http://api.google.com/search/beta2'; $host='api.google.com'; $akcja='urn:GoogleSearchAction'; $request = '<'.'?xml version=\"1.0\" encoding=\"ISO-8859-1\"?'.'> <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\"> <SOAP-ENV:Body> <typens:doGoogleSearch xmlns:typens=\"urn:GoogleSearch\"> <key xsi:type=\"xsd:string\">XXXXXXXXXXXXXXXXXXXXXXXX</key> <q xsi:type=\"xsd:string\">asdasd</q> <start xsi:type=\"xsd:int\">0</start> <maxResults xsi:type=\"xsd:int\">10</maxResults> <filter xsi:type=\"xsd:boolean\">true</filter> <restrict xsi:type=\"xsd:string\"></restrict> <safeSearch xsi:type=\"xsd:boolean\">false</safeSearch> <lr xsi:type=\"xsd:string\"></lr> <ie xsi:type=\"xsd:string\">latin</ie> <oe xsi:type=\"xsd:string\">latin</oe> </typens:doGoogleSearch> </SOAP-ENV:Body> </SOAP-ENV:Envelope>'; $header[] = \"Host: $host\"; $header[] = \"Accept: text/html;q=0.5, application/soap+xml\"; $header[] = \"Content-length: \".strlen($request); $header[] = \"Connection: close\"; $header[] = \"SOAPAction: $akcjarn\"; $header[] = $request; $ch = curl_init(); curl_setopt($ch, CURLOPT_CUSTOMREQUEST,'POST'); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HTTPHEADER, $header); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_HEADER, 1); $data=curl_exec($ch); curl_close($ch); ?>
jako output dostaje:
Content-Type: text/xml; charset=utf-8 Cache-control: private Transfer-Encoding: chunked Date: Tue, 02 Aug 2005 18:39:17 GMT Server: GFE/1.3 Connection: Close <?xml version='1.0' encoding='UTF-8'?> <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"> <SOAP-ENV:Body> <SOAP-ENV:Fault> <faultcode>SOAP-ENV:Server.Exception:</faultcode> <faultstring>java.lang.NullPointerException</faultstring> <faultactor>/search/beta2</faultactor> </SOAP-ENV:Fault> </SOAP-ENV:Body> </SOAP-ENV:Envelope> </pre>
Niezbyt rozumiem co zle zrobilem
