c#/ASP.NET向百度站长平台主动推送URL
- public static bool PushToBaiduZZ(string url)
- {
- try
- {
- using (var db = new Db.DataContext())
- {
- var m = db.Configs.FirstOrDefault(f => f.Key == "BaiduPushUrl");
- if (m == null)
- {
- return false;
- }
- string BaiduPushUrl = m.Value;
- //string.Format(BaiduPushUrl, url)
- //urlPage += ">type=original";
- Stream outstream = null;
- Stream instream = null;
- StreamReader sr = null;
- HttpWebResponse response = null;
- HttpWebRequest request = null;
- Encoding encoding = Encoding.GetEncoding("GBK");
- byte[] data = encoding.GetBytes(url);
- request = WebRequest.Create(BaiduPushUrl) as HttpWebRequest;
- request.Method = "POST";
- request.ContentType = "text/plain";
- request.ContentLength = data.Length;
- outstream = request.GetRequestStream();
- outstream.Write(data, 0, data.Length);
- outstream.Flush();
- outstream.Close();
- response = request.GetResponse() as HttpWebResponse; //直到request.GetResponse()程序才开始向目标网页发送Post请求
- instream = response.GetResponseStream();
- sr = new StreamReader(instream, encoding); //返回结果网页(html)代码
- string content = sr.ReadToEnd();//通过内容判断是否成功,成功的内容包括了success
- instream.Flush();
- instream.Close();
- sr.Close();
- return true;
- }
- }
- catch (Exception)
- {
- return false;
- }
============ 欢迎各位老板打赏~ ===========
与本文相关的文章
- · 使用jenkins远程布署.net项目
- · ASP.NET MVC分页 demo
- · ASP.NET分页组装HTML代码
- · linux asp.net用httpWebRequest或WebClient访问https站点
- · 让Windows Server 2008 + IIS 7+ ASP.NET 支持10万并发请求
- · 支持高并发的IIS Web服务器常用设置
- · LINUX下部署ASP.NET:无需安装Mono的Jexus“独立版”
- · 最新asp.net/c#使用Memcached完整示例及注意事项
- · 讨论:关于ASP.NET用Timer定时执行问题
- · ASP.NET获取工程根目录
- · Asp.Net里的Cookies用法
- · ASP.NET实现插件功能