发布:2023/1/11 11:20:39作者:管理员 来源:本站 浏览次数:636
是否还是为批量提交百度链接发愁,今天寄回来了, 下面就是百度批量提交连接的http post接口源代码解放双手,可以做成每天自动提交连接
///
/// l链接提交
///
///
///
private void SubmitLinks(object sender, EventArgs e)
{
int intNum = 0;
string strSql = @" select a.links from lw_links a";
strSql = string.Format(strSql, comboBox1.Text.Trim());
string url = string.Empty;
// 这里需要改你自己的地址
url = "http://data.zz.baidu.com/urls?site=www.ejk5.com&token=444444444444;
Service.DAL.OracleHelper.ConnectString = "Data Source=orcl;User Id=20181008;Password=20181008";
System.Data.DataTable dt = new System.Data.DataTable();
try
{
Service.DAL.OracleHelper.FillDataTable(strSql, dt);
/// 百度每次只能传1000 条,这里进行拆开 ,分批次提交连接
int m = dt.Rows.Count / 1000;
for (int i = 0; i < m+1; i++)
{
this.richTextBox1.Text = "";
for (int j = i*1000; j < (i+1)*1000; j++)
{
if (j>=dt.Rows.Count)
{
break;
}
this.richTextBox1.Text += dt.Rows[j]["links"].ToString() + "\r\n";
}
#region 提交链接 http 协议代码
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url);
Encoding encoding = Encoding.UTF8;
byte[] byteArray = Encoding.UTF8.GetBytes(this.richTextBox1.Text);
string responseData = String.Empty;
req.Method = "POST";
req.Host = "data.zz.baidu.com";
req.ContentLength = 83;
req.UserAgent = "curl/7.12.1";
req.ContentLength = byteArray.Length;
using (Stream reqStream = req.GetRequestStream())
{
reqStream.Write(byteArray, 0, byteArray.Length);
}
using (HttpWebResponse response = (HttpWebResponse)req.GetResponse())
{
using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding))
{
responseData = reader.ReadToEnd();
reader.Close();
}
}
JObject jo = JObject.Parse(responseData);
this.richTextBox1.Text += "剩余" + jo["remain"].ToString() + " 已提交:" + jo["success"].ToString() + "\r\n";
intNum += int.Parse(jo["success"].ToString());
#endregion
}
this.richTextBox1.Text += " 已提交:" + intNum.ToString();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
© Copyright 2014 - 2024 柏港建站平台 ejk5.com. 渝ICP备16000791号-4