C#推送链接URL到百度搜索资源平台提高收录量
作者:C/S框架网|www.cscode.ne  发布日期:2020-03-07 19:55:25
  C#推送链接URL到百度搜索资源平台提高收录量

C#推送链接URL到百度搜索资源平台提高收录量

百度站长平台链接提交的主动推送(实时)是最为快速的提交方式,推荐您将站点当天新产出链接立即通过此方式推送给百度,以保证新链接可以及时被百度收录。 

C# Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CSframework.Core.Common
{
  
/// <summary>
  
/// 百度相关类
  
/// </summary>
  
public class BaiDu
  {
    
/// <summary>
    
/// 推送链接至百度
    
/// </summary>
    
/// <param name="urls">链接集合</param>
    
/// <returns></returns>
    
public static string PostUrlToBaidu(string[] urls)
    {
      
try
      {
        
string formUrl = " http://data.zz.baidu.com/urls?site=www.csframework.com&token=FdSmdb3LRa4JitQp";
        
        
string formData = "";
        
        
foreach (string url in urls)
        {
          formData +
= url + "\n";
        }
        
        
byte[] postData = System.Text.Encoding.UTF8.GetBytes(formData);
        
        
// 设置提交的相关参数
        
System.Net.HttpWebRequest request = System.Net.WebRequest.Create(formUrl) as System.Net.HttpWebRequest;
        System.Text.Encoding myEncoding
= System.Text.Encoding.UTF8;
        request.Method
= "POST";
        request.KeepAlive
= false;
        request.AllowAutoRedirect
= true;
        request.ContentType
= "text/plain";
        request.UserAgent
= "curl/7.12.1";
        request.ContentLength
= postData.Length;
        
        
// 提交请求数据
        
System.IO.Stream outputStream = request.GetRequestStream();
        outputStream.Write(postData,
0, postData.Length);
        outputStream.Close();
        
        System.Net.HttpWebResponse response;
        System.IO.Stream responseStream;
        System.IO.StreamReader reader;
        
string srcString;
        response
= request.GetResponse() as System.Net.HttpWebResponse;
        responseStream
= response.GetResponseStream();
        reader
= new System.IO.StreamReader(responseStream, System.Text.Encoding.GetEncoding("UTF-8"));
        srcString
= reader.ReadToEnd();
        
string result = srcString; //返回值赋值
        
reader.Close();
        
return result;
      }
      
catch (Exception ex)
      {
        
return ex.Message;
      }
    }
  }
}

//来源:C/S框架网(www.csframework.com) QQ:23404761


上一篇 下一篇