c#百度链接批量提交源代码http接口

c#百度链接批量提交源代码
小伙伴们是否还是为批量提交百度链接发愁,今天寄回来了, 下面就是百度批量提交连接的http 接口源代码
解放双手,可以做成每天自动提交连接

///
/// 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.51jrft.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());
        }
    }

原文链接:http://www.51jrft.com/jlmb/Others/23995.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值