C # Implementation of Baidu Ping push function method _c# Tutorial

Source: Internet
Author: User

Website optimization will do one of the things, Baidu Ping, the initiative to push to Baidu

When the article is added, call the Baidu push method

Save protected void btnSubmit_Click (object sender, EventArgs e) {if (action = DTEnums.ActionEnum.Edit.ToString ())//Modify {Chkadminlevel ("Channel_" + this.channel_name + "_list", DTEnums.ActionEnum.Edit.ToString ());/check permission if (! Doedit (this.id)) {jscriptmsg error occurred during the save process! ", String.
Empty);
Return Jscriptmsg ("Modify the information successfully!")
"," article_list.aspx?channel_id= "+ this.channel_id);} else//Add {chkadminlevel ("Channel_" + this.channel_name + "_list", DTEnums.ActionEnum.Add.ToString ()); check permission int Id=doa DD (); This ID for the article returned by adding the article needs to modify the method that adds the article returns ID if (!) ( id>0)) {jscriptmsg ("error occurred during the save process!") ", String.
Empty);
Return  //Get Channel template name if (channel_id = | | channel_id = | | channel_id = = | | channel_id = | | channel_id = = 6) {string Channeltemp = new Bll.channel (). Getmodel (this.channel_id). Name.
ToString ();
String articleurl = new BasePage (). Linkurl (channeltemp + "_show", id);
string[] url = new STRING[100]; URL[1] = "http://www.qishunnet.com" + articleurl;//For example, generated URLs such as Http://www.qishunnet.com/knowledge_show_132.html String info = DTcms.Common.BaiDu.sendUrlToBaidu (URL); Jscriptmsg ("Add information success!") "," article_list.aspx?channel_id= "+ this.channel_id +" &message= Added information successfully!
Baidu Push Return message = "+ info +" URL: "+ url[1]";
Return Jscriptmsg ("Add information succeeded!")  "," article_list.aspx?channel_id= "+ this.channel_id);}

Common class Library Add Baidu Ping method

Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text; namespace Dtcms.common {///<summary>///Baidu related class///</summary> public class Baidu {///<summary>///push Send link to Baidu///</summary>///<param name= "URLs" > Link collection </param>///<returns></returns> public static string Sendurltobaidu (string[] URLs) {try {string formurl = ' http://data.zz.baidu.com/urls?site=www.qishunnet.c
Om&token=fdsmdb3lra4jitqp ";
String formData = "";
foreach (string URL in URLs) {formData + = URL + "\ n";} byte[] PostData = System.Text.Encoding.UTF8.GetBytes (FormData);
Set the related parameters for submission 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;
Submit Request data System.IO.Stream OutputStream = requests.
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; Returns the value assignment reader.
Close ();
return result; catch (Exception ex) {return ex.
message; }
}
}
}

The above is a small set to introduce the C # for you to realize the Baidu Ping push function method, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.