BlogEngine.Core/Ping/Pingback.cs

(开头部分) 3KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

#region Using

using System;
using System.IO;
using System.Xml;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using BlogEngine.Core;

#endregion

namespace BlogEngine.Core.Ping
{
  /// <summary>
  /// Sends pingbacks to website that the blog links to.
  /// </summary>
  public static class Pingback
  {

    /// <summary>
    /// Sends pingbacks to the targetUrl.
    /// </summary>
    public static void Send(Uri sourceUrl, Uri targetUrl)
    {
			if (!BlogSettings.Instance.EnablePingBackSend)
				return;

      if (sourceUrl == null || targetUrl == null)
        return;

      try
      {
        HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(targetUrl);
        request.Credentials = CredentialCache.DefaultNetworkCredentials;
        HttpWebResponse response = (HttpWebResponse)request.GetResponse();
        string pingUrl = (string.IsNullOrEmpty(response.Headers["x-pingback"])) ? response.Headers["x-pingback"] : response.Headers["pingback"];
        Uri url;
        if (!string.IsNullOrEmpty(pingUrl) && Uri.TryCreate(pingUrl, UriKind.Absolute, out url))
        {
          OnSending(url);
          request = (HttpWebRequest)HttpWebRequest.Create(url);
          request.Method = "POST";
          request.Timeout = 10000;
          request.ContentType = "text/xml";
          request.ProtocolVersion = HttpVersion.Version11;
					request.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 6.0)";
          AddXmlToRequest(sourceUrl, targetUrl, request);
          request.GetResponse();
          OnSent(url);
        }
      }
      catch (Exception)
      {
        // Stops unhandled exceptions that can cause the app pool to recycle
      }
    }

    /// <summary>
    /// Adds the XML to web request. The XML is the standard
后面还有 59 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。