asp.net主动推送百度seo
电脑版发表于:2018/12/31 16:26
虽然可以使用百度提供的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>() { "你的链接"});