您目前尚未登陆,请选择【登陆】或【注册
首页->博客论坛->LiveBlog v1.0测试版源码>>LiveBlog.Core/Ping/Trackback.cs>>源码在线查看
温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:LiveBlog v1.0测试版源码
当前文件:文件类型 LiveBlog/LiveBlog.Core/Ping/Trackback.cs打开代码结构图
普通视图
		            
1Using 12 13namespace LiveBlog.Core.Ping 14{ 15 /// <summary> 16 /// 17 /// </summary> 18 public static class Trackback 19 { 20 21 /// <summary> 22 /// 23 /// </summary> 24 /// <param name="message"></param> 25 /// <returns></returns> 26 public static bool Send(TrackbackMessage message) 27 { 28 if (!BlogSettings.Instance.EnableTrackBackSend) 29 return false; 30 31 if (message == null) 32 throw new ArgumentNullException("message"); 33 34 OnSending(message.UrlToNotifyTrackback); 35 //Warning:next line if for local debugging porpuse please donot remove it until you need to 36 //tMessage.PostURL = new Uri("http://www.artinsoft.com/webmaster/trackback.html"); 37 HttpWebRequest request = (HttpWebRequest)System.Net.HttpWebRequest.Create(message.UrlToNotifyTrackback); //HttpHelper.CreateRequest(trackBackItem); 38 request.Credentials = CredentialCache.DefaultNetworkCredentials; 39 request.Method = "POST"; 40 request.ContentLength = message.ToString().Length; 41 request.ContentType = "application/x-www-form-urlencoded"; 42 request.KeepAlive = false; 43 request.Timeout = 10000; 44 45 using (StreamWriter myWriter = new StreamWriter(request.GetRequestStream())) 46 { 47 myWriter.Write(message.ToString()); 48 } 49 50 bool result = false; 51 HttpWebResponse response; 52 try 53 { 54 response = (HttpWebResponse)request.GetResponse(); 55 OnSent(message.UrlToNotifyTrackback); 56 string answer; 57 using (System.IO.StreamReader sr = new System.IO.StreamReader(response.GetResponseStream())) 58 { 59 answer = sr.ReadToEnd(); 60 } 61 62 if (response.StatusCode == HttpStatusCode.OK) 63 { 64 //todo:This could be a strict XML parsing if necesary/maybe logging activity here too 65 if (answer.Contains("<error>0</error>")) 66 { 67 result = true; 68 } 69 else 70 { 71 result = false; 72 } 73 } 74 else 75 { 76 result = false; 77 } 78 } 79 catch //(WebException wex) 80 { 81 result = false; 82 } 83 return result; 84 } 85 86 ... 113 114 } 115 116 /// <summary> 117 /// 118 /// </summary> 119 public class TrackbackMessage 120 { 121 /// <summary> 122 /// 123 /// </summary> 124 private string _Title; 125 126 /// <summary> 127 /// 128 /// </summary> 129 public string Title 130 { 131 get { return _Title; } 132 set { _Title = value; } 133 } 134 135 /// <summary> 136 /// 137 /// </summary> 138 private Uri _PostUrl; 139 140 /// <summary> 141 /// 142 /// </summary> 143 public Uri PostUrl 144 { 145 get { return _PostUrl; } 146 set { _PostUrl = value; } 147 } 148 149 /// <summary> 150 /// 151 /// </summary> 152 private string _Excerpt; 153 154 /// <summary> 155 /// 156 /// </summary> 157 public string Excerpt 158 { 159 get { return _Excerpt; } 160 set { _Excerpt = value; } 161 } 162 163 /// <summary> 164 /// 165 /// </summary> 166 private string _BlogName; 167 168 /// <summary> 169 /// 170 /// </summary> 171 public string BlogName 172 { 173 get { return _BlogName; } 174 set { _BlogName = value; } 175 } 176 177 /// <summary> 178 /// 179 /// </summary> 180 private Uri _UrlToNotifyTrackback; 181 182 /// <summary> 183 /// 184 /// </summary> 185 public Uri UrlToNotifyTrackback 186 { 187 get { return _UrlToNotifyTrackback; } 188 set { _UrlToNotifyTrackback = value; } 189 } 190 191 /// <summary> 192 /// 193 /// </summary> 194 /// <param name="post"></param> 195 /// <param name="urlToNotifyTrackback"></param> 196 public TrackbackMessage(IPublishable item, Uri urlToNotifyTrackback) 197 { 198 if (item == null) 199 throw new ArgumentNullException("post"); 200 201 Title = item.Title; 202 PostUrl = item.AbsoluteLink; 203 Excerpt = item.Title; 204 BlogName = BlogSettings.Instance.Name; 205 UrlToNotifyTrackback = urlToNotifyTrackback; 206 } 207 208 /// <summary> 209 /// 210 /// </summary> 211 /// <returns></returns> 212 public override string ToString() 213 { 214 if (string.IsNullOrEmpty(UrlToNotifyTrackback.Query)) 215 { 216 return String.Format(CultureInfo.InvariantCulture, "?title={0}&url={1}&excerpt={2}&blog_name={3}", Title, PostUrl, Excerpt, BlogName); 217 } 218 else 219 { 220 return String.Format(CultureInfo.InvariantCulture, "&title={0}&url={1}&excerpt={2}&blog_name={3}", Title, PostUrl, Excerpt, BlogName); 221 } 222 } 223 224 } 225}
还没有找到您心仪的内容?请用.net源码大搜捕
代码片断 打包下载该项目完整源码:LiveBlog v1.0测试版源码