百度资源平台API提交推送示例
百度资源平台API提交推送示例分为四种,分别是cURL推送示例、post推送示例、php推送示例、ruby推送示例。
1、curl推送示例
将要提交的链接按照每行一条的格式写入一个文本文件中,命名此文件为urls.txt,然后进入该文件所在目录,执行如下命令:
curl -H 'Content-Type:text/plain' --data-binary @urls.txt "http://data.zz.baidu.com/urls?appid=1584274397481205&token=lZv5hfmigdZjU7Ws&type=realtime"
使用php、python、java等可以参照这个过程推送结构化数据。
2、post推送示例
POST /urls?appid=1584274397481205&token=lZv5hfmigdZjU7Ws&type=realtime?HTTP/1.1
User-Agent: curl/7.12.1
Host: data.zz.baidu.com
Content-Type: text/plain
Content-Length: 83
http://www.example.com/1.html
http://www.example.com/2.html
3、php推送示例
$urls = array( ? ?'http://www.example.com/1.html', ? ?'http://www.example.com/2.html',);$api = 'http://data.zz.baidu.com/urls?appid=1584274397481205&token=lZv5hfmigdZjU7Ws&type=realtime'$ch = curl_init();$options = ?array( ? ?CURLOPT_URL => $api, ? ?CURLOPT_POST => true, ? ?CURLOPT_RETURNTRANSFER => true, ? ?CURLOPT_POSTFIELDS => implode(" ", $urls), ? ?CURLOPT_HTTPHEADER => array('Content-Type: text/plain'),);curl_setopt_array($ch, $options);$result = curl_exec($ch);echo $result;
4、ruby推送示例
require 'net/http'
urls = ['http://www.example.com/1.html', 'http://www.example.com/2.html']
uri = URI.parse('http://data.zz.baidu.com/urls?appid=1584274397481205&token=lZv5hfmigdZjU7Ws&type=realtime')
req = Net::HTTP::Post.new(uri.request_uri)
req.body = urls.join(" ")
req.content_type = 'text/plain'
res = Net::HTTP.start(uri.hostname, uri.port) { |http| http.request(req) }
puts res.body