DoboWiki
Top
> 自由区/Webサービス紹介/Yahoo! Search Web Services/Spelling Suggestionコード(C#) をテンプレートにして作成
自由区/Webサービス紹介/Yahoo! Search Web Services/Spelling Suggestionコード(C#) をテンプレートにして作成
開始行:
*Yahoo! Search Web Services: Spelling Suggestion サンプル...
以下のコードを実行するには、xsd.exeで生成されたクラスが必...
#attach(noform)
#code(csharp){{
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional...
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Button1_Click(object sender, EventArgs...
{
//URLを構築する
string requestUrl =
"http://api.search.yahoo.com/WebSearchService...
//アプリケーションIDを指定(必ず指定すること)
requestUrl += "?appid=XXXXX";
//クエリー。UTF-8エンコードする。
requestUrl += "&query=" + Server.UrlEncode(TextBo...
//HttpWebRequestの作成
System.Net.HttpWebRequest request =
(System.Net.HttpWebRequest)System.Net.WebRequ...
requestUrl);
System.Net.HttpWebResponse response = null;
Yahoo.us.WebSearchSpellingResponse.ResultSet res;
try
{
//レスポンスの取得
response = (System.Net.HttpWebResponse)reques...
System.IO.Stream strm = response.GetResponseS...
//サーバーから返されたXMLデータを解析
//xsd.exeで作成したクラスに逆シリアル化
System.Xml.Serialization.XmlSerializer serial...
new System.Xml.Serialization.XmlSerializer(
typeof(Yahoo.us.WebSearchSpellingResponse...
res = (Yahoo.us.WebSearchSpellingResponse.Res...
serializer.Deserialize(strm);
}
catch (Exception ex)
{
Label1.Text = "エラー:" + Server.HtmlEncode(...
return;
}
finally
{
if (response != null)
response.Close();
}
//結果を表示
if (res.Result == "")
{
Label1.Text = "提案はありません。";
}
else
{
Label1.Text = res.Result;
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Yahoo! Search Web Services: Spelling Suggestio...
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:T...
<asp:Button ID="Button1" runat="server"
OnClick="Button1_Click" Text="送信" /><br />
<br />
<asp:Label ID="Label1" runat="server" EnableViewS...
</asp:Label></div>
</form>
<!-- Begin Yahoo Web Services HTML Attribution Snippet -->
<a href="http://developer.yahoo.net/about/">
Web Services by Yahoo!
</a>
<!-- End Yahoo Web Services HTML Attribution Snippet -->
</body>
</html>
}}
//これより下は編集しないでください
#pageinfo(,2006-09-12 (火) 02:06:50,DOBON!,2006-09-12 (火...
終了行:
*Yahoo! Search Web Services: Spelling Suggestion サンプル...
以下のコードを実行するには、xsd.exeで生成されたクラスが必...
#attach(noform)
#code(csharp){{
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional...
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Button1_Click(object sender, EventArgs...
{
//URLを構築する
string requestUrl =
"http://api.search.yahoo.com/WebSearchService...
//アプリケーションIDを指定(必ず指定すること)
requestUrl += "?appid=XXXXX";
//クエリー。UTF-8エンコードする。
requestUrl += "&query=" + Server.UrlEncode(TextBo...
//HttpWebRequestの作成
System.Net.HttpWebRequest request =
(System.Net.HttpWebRequest)System.Net.WebRequ...
requestUrl);
System.Net.HttpWebResponse response = null;
Yahoo.us.WebSearchSpellingResponse.ResultSet res;
try
{
//レスポンスの取得
response = (System.Net.HttpWebResponse)reques...
System.IO.Stream strm = response.GetResponseS...
//サーバーから返されたXMLデータを解析
//xsd.exeで作成したクラスに逆シリアル化
System.Xml.Serialization.XmlSerializer serial...
new System.Xml.Serialization.XmlSerializer(
typeof(Yahoo.us.WebSearchSpellingResponse...
res = (Yahoo.us.WebSearchSpellingResponse.Res...
serializer.Deserialize(strm);
}
catch (Exception ex)
{
Label1.Text = "エラー:" + Server.HtmlEncode(...
return;
}
finally
{
if (response != null)
response.Close();
}
//結果を表示
if (res.Result == "")
{
Label1.Text = "提案はありません。";
}
else
{
Label1.Text = res.Result;
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Yahoo! Search Web Services: Spelling Suggestio...
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:T...
<asp:Button ID="Button1" runat="server"
OnClick="Button1_Click" Text="送信" /><br />
<br />
<asp:Label ID="Label1" runat="server" EnableViewS...
</asp:Label></div>
</form>
<!-- Begin Yahoo Web Services HTML Attribution Snippet -->
<a href="http://developer.yahoo.net/about/">
Web Services by Yahoo!
</a>
<!-- End Yahoo Web Services HTML Attribution Snippet -->
</body>
</html>
}}
//これより下は編集しないでください
#pageinfo(,2006-09-12 (火) 02:06:50,DOBON!,2006-09-12 (火...
ページ名:
▲
▼
[
トップ
] [
新規
|
子ページ作成
|
一覧
|
単語検索
|
最終更新
|
ヘルプ
]