ASP Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript

ASP Examples

ASP String
ASP Byte Array
Bounced Mail
Bz2
Character Encoding
CSV
Digital Certificates
Digital Signatures
Email
FTP
HTML-to-XML
HTTP
IMAP
Encryption
MHT / HTML Email
POP3
RSA
S/MIME
SMTP
Socket
Spider
SSH
SSH Tunnel
SSH Key
SFTP
Tar
ASP Upload
XML
XMP
Zip Compression

More Examples...
Email Object
FileAccess
RSS
Atom
Self-Extractor
Service
PPMD
Deflate
DH Key Exchange
DSA

Unreleased...
Bzip2
LZW
Icon

 

 

 

 

 

 

Add Google Search to euc-kr Korean ASP Page

ASP example code showing how to use the Google Search API and convert the utf-8 XML response to euc-kr for display on a Korean ASP page.

<%@ LANGUAGE="VBSCRIPT" %>
<html>

<head>
<meta HTTP-EQUIV="Content-Type" CONTENT="text/html;CHARSET=euc-kr">
<title>Sample Korean Google Search</title>
</head>

<body bgcolor="#FFFFFF">

<% 

Dim GoogleUrl,GoogleKey,SoapText,ObjXml,UnicodeResponse,CXml

' Get a key from Google...
GoogleKey = "0000000000000000000000000000"

' Create a SOAP message for a Google Search Request
' The language is set to Korean
SoapText = "<?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>" & _
"    <ns1:doGoogleSearch xmlns:ns1=""urn:GoogleSearch"" " & _
"         SOAP-ENV:encodingStyle=""http://schemas.xmlsoap.org/soap/encoding/"">" & _
"      <key xsi:type=""xsd:string"">"&GoogleKey&"</key>" & _
"      <q xsi:type=""xsd:string"">Korean newspaper</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"">lang_ko</lr>" & _
"      <ie xsi:type=""xsd:string"">latin1</ie>" & _
"      <oe xsi:type=""xsd:string"">latin1</oe>" & _
"    </ns1:doGoogleSearch>" & _
"  </SOAP-ENV:Body>" & _
"</SOAP-ENV:Envelope>"

GoogleUrl = "http://api.google.com/search/beta2"  

' Make the SOAP Google API Call
Set ObjXml = CreateObject("Microsoft.XMLHTTP") 
ObjXml.open "POST",GoogleUrl,"False" 
ObjXml.setRequestHeader "Man", "POST"+" "+GoogleUrl+" HTTP/1.1"  
ObjXml.setRequestHeader "MessageType", "CALL"  
ObjXml.setRequestHeader "Content-Type", "text/xml"  
ObjXml.send SoapText  

' Get the Google Search Response
' Google requests and responses are always utf-8.
' However, when the Microsoft.XMLHTTP object returns the response
' text, it is already converted to a Unicode string.
UnicodeResponse = objXML.responseText 
Set ObjXml = Nothing 

' Create a Chilkat ASP XML object for easy parsing.
' ASP XML is a free ASP component from Chilkat Software.
set CXml = Server.CreateObject("AspXml.AspXml")
CXml.LoadXml UnicodeResponse

' This page requires euc-kr
' Create a Chilkat Charset Conversion component for conversion from Unicode
' The Chilkat Charset component is not a free component, and can
' be licenced from Chilkat Software, Inc.
set cc = Server.CreateObject("ChilkatCharset2.ChilkatCharset2")

' Any value passed to UnlockComponent begins the 30-day trial.
cc.UnlockComponent "30-day trial"
cc.ToCharset = "euc-kr"

' Quickly navigate to the result elements.
set resultElements = CXml.SearchForTag(Nothing,"resultElements")
if not (resultElements is nothing) then

	' Find the first item
	set item = resultElements.SearchForTag(Nothing,"item")

	while not (item is nothing)
	
		Response.Write "Title: " 
		title = item.GetChildContent("title")
		if Len(title) > 0 then
			Response.BinaryWrite cc.ConvertFromUnicode(title)
		end if
		Response.Write "<br>"
		
		Response.Write "URL: " & item.GetChildContent("URL") & "<br>"

		Response.Write "Summary: " 
		summary = item.GetChildContent("summary")
		if Len(summary) > 0 then
			Response.BinaryWrite cc.ConvertFromUnicode(summary)
		end if
		Response.Write "<br><br>"
		
		set item = item.NextSibling()
	wend
else
	Response.Write CXml.GetXml()
end if

%>

</body>
</html>
 

Need a specific example? Send a request to support@chilkatsoft.com

© 2000-2008 Chilkat Software, Inc. All Rights Reserved.