index-dotnet.aspx.cs
上传用户:guomengjz
上传日期:2022-06-06
资源大小:726k
文件大小:2k
源码类别:

搜索引擎

开发平台:

C/C++

  1. using System;
  2. using System.Collections;
  3. using System.Configuration;
  4. using System.Data;
  5. using System.Web;
  6. using System.Web.Security;
  7. using System.Web.UI;
  8. using System.Web.UI.HtmlControls;
  9. using System.Web.UI.WebControls;
  10. using System.Web.UI.WebControls.WebParts;
  11. namespace WebApp.demo
  12. {
  13.     public partial class index_dotnet : System.Web.UI.Page
  14.     {
  15.         protected void Page_Load(object sender, EventArgs e)
  16.         {
  17.             String SearchPortal="http://www.test.com/totindex.aspx";//淘特搜索引擎索引接口地址
  18.             String IndexKey="totsearchengine01";//接口访问key,请通过搜索引擎中的web.config查找
  19.             String str="";
  20.             //添加索引
  21.             str=PostUrl(SearchPortal,"key="+IndexKey+"&action=insert&id=1&Title=测一下试&Content=test&Categoryid=0&Summary=test&Photo=a&ModDate=2010-1-1&LinkUrl=test");
  22.             Response.Write(str);
  23.             Response.Write("<br>");
  24.             //删除索引
  25.             //str=PostUrl(SearchPortal,"key="+IndexKey+"&action=delete&id=1");
  26.             Response.Write(str);
  27.         }
  28.         private string PostUrl(string URI, string Parameters)
  29.         {
  30.             System.Net.WebRequest req = System.Net.WebRequest.Create(URI);
  31.             //req.Proxy = new System.Net.WebProxy(ProxyString, true);
  32.             req.ContentType = "application/x-www-form-urlencoded";
  33.             req.Method = "POST";
  34.             byte[] bytes = System.Text.Encoding.UTF8.GetBytes(Parameters);
  35.             req.ContentLength = bytes.Length;
  36.             System.IO.Stream os = req.GetRequestStream();
  37.             os.Write(bytes, 0, bytes.Length);
  38.             os.Close();
  39.             System.Net.WebResponse resp = req.GetResponse();
  40.             if (resp == null) return null;
  41.             System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream());
  42.             return sr.ReadToEnd().Trim();
  43.         }
  44.     }
  45. }