您目前尚未登陆,请选择【登陆】或【注册
首页->博客论坛->LiveBlog v1.0测试版源码>>LiveBlog.Core/Ping/Pingback.cs>>源码在线查看
温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:LiveBlog v1.0测试版源码
当前文件:文件类型 LiveBlog/LiveBlog.Core/Ping/Pingback.cs打开代码结构图
普通视图
		            
1Using 12 13namespace LiveBlog.Core.Ping 14{ 15 /// <summary> 16 /// Sends pingbacks to website that the blog links to. 17 /// </summary> 18 public static class Pingback 19 { 20 21 /// <summary> 22 /// Sends pingbacks to the targetUrl. 23 /// </summary> 24 public static void Send(Uri sourceUrl, Uri targetUrl) 25 { 26 if (!BlogSettings.Instance.EnablePingBackSend) 27 return; 28 29 if (sourceUrl == null || targetUrl == null) 30 return; 31 32 try 33 { 34 HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(targetUrl); 35 request.Credentials = CredentialCache.DefaultNetworkCredentials; 36 HttpWebResponse response = (HttpWebResponse)request.GetResponse(); 37 string pingUrl = response.Headers["x-pingback"]; 38 Uri url; 39 if (!string.IsNullOrEmpty(pingUrl) && Uri.TryCreate(pingUrl, UriKind.Absolute, out url)) 40 { 41 OnSending(url); 42 request = (HttpWebRequest)HttpWebRequest.Create(url); 43 request.Method = "POST"; 44 request.Timeout = 10000; 45 request.ContentType = "text/xml"; 46 request.ProtocolVersion = HttpVersion.Version11; 47 request.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 6.0)"; 48 AddXmlToRequest(sourceUrl, targetUrl, request); 49 request.GetResponse(); 50 OnSent(url); 51 } 52 } 53 catch (Exception) 54 { 55 // Stops unhandled exceptions that can cause the app pool to recycle 56 } 57 } 58 59 /// <summary> 60 /// Adds the XML to web request. The XML is the standard 61 /// XML used by RPC-XML requests. 62 /// </summary> 63 private static void AddXmlToRequest(Uri sourceUrl, Uri targetUrl, HttpWebRequest webreqPing) 64 { 65 Stream stream = (Stream)webreqPing.GetRequestStream(); 66 using (XmlTextWriter writer = new XmlTextWriter(stream, Encoding.ASCII)) 67 { 68 writer.WriteStartDocument(true); 69 writer.WriteStartElement("methodCall"); 70 writer.WriteElementString("methodName", "pingback.ping"); 71 writer.WriteStartElement("params"); 72 73 writer.WriteStartElement("param"); 74 writer.WriteStartElement("value"); 75 writer.WriteElementString("string", sourceUrl.ToString()); 76 writer.WriteEndElement(); 77 writer.WriteEndElement(); 78 79 writer.WriteStartElement("param"); 80 writer.WriteStartElement("value"); 81 writer.WriteElementString("string", targetUrl.ToString()); 82 writer.WriteEndElement(); 83 writer.WriteEndElement(); 84 85 writer.WriteEndElement(); 86 writer.WriteEndElement(); 87 } 88 } 89 90 Events 117 118 } 119} 120
还没有找到您心仪的内容?请用.net源码大搜捕
代码片断 打包下载该项目完整源码:LiveBlog v1.0测试版源码
51Aspx.com 版权所有 CopyRight © 2000-2008. 京ICP备06046876号