using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Net;
public partial class _Default : System.Web.UI.Page
{
// #region Post/Get请求数据 static
string domainUrl = “www.sunsharer.cn”;//站点
string secretKey = “bba43ace2106730f615b8l7aX8wH2”;//token,在百度站长工具里申请
string url;
string postUrl =“https://www.sunsharer.cn/”//提交的页面
string data;
protected void Page_Load(object sender, EventArgs e)
{
url = string.Format(“http://data.zz.baidu.com/urls?site={0}&token={1}”, domainUrl, secretKey);
data = SendRequest(url, postUrl);
Response.Write(data);
}
public string SendRequest(string requestUrl, string data)
{
HttpWebRequest httpWebRequest = null;
string returnData = "";
try
{
httpWebRequest = (HttpWebRequest)WebRequest.Create(requestUrl);
httpWebRequest.Method = WebRequestMethods.Http.Post;
httpWebRequest.ContentType = "application/json; charset=utf-8";
httpWebRequest.Proxy = null;
httpWebRequest.KeepAlive = false;
httpWebRequest.ServicePoint.UseNagleAlgorithm = false;
httpWebRequest.AllowWriteStreamBuffering = false;
httpWebRequest.Accept = "application/json";
byte[] dataArray = Encoding.UTF8.GetBytes(data);
httpWebRequest.ContentLength = dataArray.Length;
using (Stream requestStream = httpWebRequest.GetRequestStream())
{
requestStream.Write(dataArray, 0, dataArray.Length);
HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
StreamReader streamReader = new StreamReader(httpWebResponse.GetResponseStream());
returnData = streamReader.ReadToEnd();
streamReader.Close();
httpWebResponse.Close();
}
httpWebRequest.Abort();
}
catch (Exception ex)
{
Response.Write(ex);
// throw ex;
}
finally
{
if (httpWebRequest != null)
{
httpWebRequest.Abort();
httpWebRequest = null;
}
}
return returnData;
}
}