index-dotnet.aspx.cs
上传用户:taiyokogyo
上传日期:2022-04-20
资源大小:365k
文件大小:2k
- using System;
- using System.Collections;
- using System.Configuration;
- using System.Data;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.HtmlControls;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- namespace WebApp.demo
- {
- public partial class index_dotnet : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- String SearchPortal="http://www.test.com/totindex.aspx";//淘特搜索引擎索引接口地址
- String IndexKey="totsearchengine01";//接口访问key,请通过搜索引擎中的web.config查找
- String str="";
- //添加索引
- str=PostUrl(SearchPortal,"key="+IndexKey+"&action=insert&id=1&Title=测一下试&Content=test&Categoryid=0&Summary=test&Photo=a&ModDate=2010-1-1&LinkUrl=test");
- Response.Write(str);
- Response.Write("<br>");
- //删除索引
- //str=PostUrl(SearchPortal,"key="+IndexKey+"&action=delete&id=1");
- Response.Write(str);
- }
- private string PostUrl(string URI, string Parameters)
- {
- System.Net.WebRequest req = System.Net.WebRequest.Create(URI);
- //req.Proxy = new System.Net.WebProxy(ProxyString, true);
- req.ContentType = "application/x-www-form-urlencoded";
- req.Method = "POST";
- byte[] bytes = System.Text.Encoding.UTF8.GetBytes(Parameters);
- req.ContentLength = bytes.Length;
- System.IO.Stream os = req.GetRequestStream();
- os.Write(bytes, 0, bytes.Length);
- os.Close();
- System.Net.WebResponse resp = req.GetResponse();
- if (resp == null) return null;
- System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream());
- return sr.ReadToEnd().Trim();
- }
- }
- }