排名
6
文章
6
粉丝
16
评论
8
{{item.articleTitle}}
{{item.blogName}} : {{item.content}}
ICP备案 :渝ICP备18016597号-1
网站信息:2018-2024TNBLOG.NET
技术交流:群号656732739
联系我们:contact@tnblog.net
公网安备:50010702506256
欢迎加群交流技术
分类:
.NET
虽然可以使用百度提供的js自动推送,但是估计度娘还是希望主动推送一点。
哈哈^_^,女孩子嘛大多都喜欢被动一点。
public class SEOTools { public static string PostUrlToBaidu(List<string> urls) { try { string formUrl = " token "; 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; } } }
使用:
SEOTools.PostUrlToBaidu(new List<string>() { "你的链接"});
欢迎加群讨论技术,群:677373950(满了,可以加,但通过不了),2群:656732739
评价