后台代码Default.cs:
以下是引用片段:
1using System;
2using System.Data;
3using System.Configuration;
4using System.Web;
5using System.Web.Security;
6using System.Web.UI;
7using System.Web.UI.WebControls;
8using System.IO;
9using System.Net;
10using Anthem;
11
12public partial class _Default : System.Web.UI.Page, ICallbackEventHandler
13{
14 protected void Page_Load(object sender, EventArgs e)
15 {
16 Anthem.Manager.Register(this);
17
18 }
19
20 回调的固定格式#region 回调的固定格式
21 public string str_content;
22
23 public void RaiseCallbackEvent(string the_string)
24 {
25 str_content = the_string;
26 }
27
28 /**////
29 /// 回调,解析客户端的参数
30 ///
31 ///
32 public string GetCallbackResult()
33 {
34
35 string[] parts = str_content.Split('|');
36 object[] theArgList = new object[parts.Length - 1];
37 for (int int_index = 1; int_index < parts.Length; int_index++)
38 theArgList[int_index - 1] = parts[int_index];
39 return (string)GetType().GetMethod(parts[0]).Invoke(this, theArgList);
40 }
41 #endregion
42
43 解析url的页面内容的方法体#region 解析url的页面内容的方法体
44 /**////
45 /// Anthem方式,解析获取的url的页面内容
46 ///
47 /// url
48 ///
49 [Anthem.Method]
50 public string ShowWeatherByAnthem()
51 {
52
53 WebRequest request = WebRequest.Create(Text1.Value);
54 request.Credentials = CredentialCache.DefaultCredentials;
55 HttpWebResponse response = (HttpWebResponse)request.GetResponse();
56 Stream dataStream = response.GetResponseStream();
57 StreamReader reader = new StreamReader(dataStream, System.Text.Encoding.Default);
58 string str = reader.ReadToEnd();
59 return str.Substring(220);
60
61 }
62 //
63 //回调方式,解析获取的url的页面内容
64 //
65 //
66 //
67 public string ShowWeatherByCall(string url)
68 {
69 WebRequest request = WebRequest.Create(url);
70 request.Credentials = CredentialCache.DefaultCredentials;
71 HttpWebResponse response = (HttpWebResponse)request.GetResponse();
72 Stream dataStream = response.GetResponseStream();
73 StreamReader reader = new StreamReader(dataStream, System.Text.Encoding.Default);
74 string str = reader.ReadToEnd();
75 return str.Substring(220);
76
77 }
78 #endregion
79}
80
来源:天极