分类目录

链接

2017 年 7 月
 12
3456789
10111213141516
17181920212223
24252627282930
31  

近期文章

热门标签

新人福利,免费薅羊毛

现在位置:    首页 > .NET > 正文
c#/ASP.NET向百度站长平台主动推送URL
.NET 暂无评论 阅读(723)
  1. public static bool PushToBaiduZZ(string url)
  2.         {
  3.             try
  4.             {
  5.  
  6.                 using (var db = new Db.DataContext())
  7.                 {
  8.                     var m = db.Configs.FirstOrDefault(=> f.Key == "BaiduPushUrl");
  9.                     if (== null)
  10.                     {
  11.                         return false;
  12.                     }
  13.                     string BaiduPushUrl = m.Value;
  14.                     //string.Format(BaiduPushUrl, url) 
  15.                     //urlPage += ">type=original";
  16.                     Stream outstream = null;
  17.                     Stream instream = null;
  18.                     StreamReader sr = null;
  19.                     HttpWebResponse response = null;
  20.                     HttpWebRequest request = null;
  21.                     Encoding encoding = Encoding.GetEncoding("GBK");
  22.                     byte[] data = encoding.GetBytes(url);
  23.                     request = WebRequest.Create(BaiduPushUrl) as HttpWebRequest;
  24.                     request.Method = "POST";
  25.                     request.ContentType = "text/plain";
  26.                     request.ContentLength = data.Length;
  27.                     outstream = request.GetRequestStream();
  28.                     outstream.Write(data, 0, data.Length);
  29.                     outstream.Flush();
  30.                     outstream.Close();
  31.                     response = request.GetResponse() as HttpWebResponse;            //直到request.GetResponse()程序才开始向目标网页发送Post请求            
  32.                     instream = response.GetResponseStream();
  33.                     sr = new StreamReader(instream, encoding); //返回结果网页(html)代码            
  34.                     string content = sr.ReadToEnd();//通过内容判断是否成功,成功的内容包括了success
  35.                     instream.Flush();
  36.                     instream.Close();
  37.                     sr.Close();
  38.                     return true;
  39.                 }
  40.             }
  41.             catch (Exception)
  42.             {
  43.                 return false;
  44.             }

============ 欢迎各位老板打赏~ ===========

本文版权归Bruce's Blog所有,转载引用请完整注明以下信息:
本文作者:Bruce
本文地址:c#/ASP.NET向百度站长平台主动推送URL | Bruce's Blog

发表评论

留言无头像?