Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ C MFC Delphi FoxPro Java Perl PHP Python Ruby SQL Server VBScript
|
Using XMLHTTP with GOOGLE's SOAP API
C# example showing how to do a Google search using Google's SOAP API. Chilkat.Http http = new Chilkat.Http(); bool unlocked = http.UnlockComponent("Any string begins 30-day trial"); if (!unlocked) { MessageBox.Show("Failed to unlock HTTP component"); return; } // Results in China may not be the same as elsewhere... string search = "China Internet censorship"; string soapRequest = "<?xml version='1.0' encoding='UTF-8'?>"+"\n\n"+"<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><ns1:doGoogleSearch"+ " xmlns:ns1=\"urn:GoogleSearch\""+ " SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">"+ "<key xsi:type=\"xsd:string\">YOUR_GOOGLE_API_KEY_HERE</key> <q"+ " xsi:type=\"xsd:string\">"+search+"</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\">latin1</ie> <oe"+ " xsi:type=\"xsd:string\">latin1</oe>"+ "</ns1:doGoogleSearch>"+ "</SOAP-ENV:Body></SOAP-ENV:Envelope>"; Chilkat.HttpRequest req = new Chilkat.HttpRequest(); req.UseXmlHttp(soapRequest); req.Path = "/search/beta2"; req.AddHeader("MessageType","CALL"); bool ssl = false; // Set this to true to use HTTPS Chilkat.HttpResponse resp = http.SynchronousRequest("api.google.com",80,false,req); if (resp == null) { MessageBox.Show(http.LastErrorText); return; } // Did we get a successful response? if (resp.StatusCode == 200) { // Success! // Display the XML document we received. textBox1.Text = resp.BodyStr; // Load the XML into a Chilkat.Xml object. Chilkat.Xml xml = new Chilkat.Xml(); xml.LoadXml(resp.BodyStr); string strUrls = ""; // Pick out all the URLs and display them. Chilkat.Xml xUrl = xml.SearchForTag(null,"URL"); while (xUrl != null) { strUrls += xUrl.Content + "\r\n"; xUrl = xml.SearchForTag(xUrl,"URL"); } MessageBox.Show(strUrls); } else { // Failed! // Show the full response header... MessageBox.Show(resp.Header); } Important: The download for this
example does not contain the ChilkatDotNet2.dll which |
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2008 Chilkat Software, Inc. All Rights Reserved.