This is a Baidu webmaster platform push Case:
Post case:
Post/urls?site=www.nantongzt.com&token=xxxxxx 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
Examples of PHP pushes:
$urls = array( 'http://www.example.com/1.html', 'http://www.example.com/2.html',);$api = 'http://data.zz.baidu.com/urls?site=www.nantongzt.com&token=xxxxxx';$ch = curl_init();$options = array( CURLOPT_URL => $api, CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_POSTFIELDS => implode("\n", $urls), CURLOPT_HTTPHEADER => array('Content-Type: text/plain'),);curl_setopt_array($ch, $options);$result = curl_exec($ch);echo $result;
Examples of 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?site=www.nantongzt.com&token=xxxxxx')req = Net::HTTP::Post.new(uri.request_uri)req.body = urls.join("\n")req.content_type = 'text/plain'res = Net::HTTP.start(uri.hostname, uri.port) { |http| http.request(req) }puts res.body
In fact, it should be very simple, that is, how to submit data with Python post.
But look at PHP and Ruby's code is not very similar ~
Want to have a person to point, personal comparison dish ~ Hope to have a detailed translation, thank you!
Reply content:
This is a Baidu webmaster platform push Case:
Post case:
Post/urls?site=www.nantongzt.com&token=xxxxxx 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
Examples of PHP pushes:
$urls = array( 'http://www.example.com/1.html', 'http://www.example.com/2.html',);$api = 'http://data.zz.baidu.com/urls?site=www.nantongzt.com&token=xxxxxx';$ch = curl_init();$options = array( CURLOPT_URL => $api, CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_POSTFIELDS => implode("\n", $urls), CURLOPT_HTTPHEADER => array('Content-Type: text/plain'),);curl_setopt_array($ch, $options);$result = curl_exec($ch);echo $result;
Examples of 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?site=www.nantongzt.com&token=xxxxxx')req = Net::HTTP::Post.new(uri.request_uri)req.body = urls.join("\n")req.content_type = 'text/plain'res = Net::HTTP.start(uri.hostname, uri.port) { |http| http.request(req) }puts res.body
In fact, it should be very simple, that is, how to submit data with Python post.
But look at PHP and Ruby's code is not very similar ~
Want to have a person to point, personal comparison dish ~ Hope to have a detailed translation, thank you!
#coding=utf-8import requestsurls = [ 'http://www.example.com/1.html', 'http://www.example.com/2.html']api = 'http://data.zz.baidu.com/urls?site=www.nantongzt.com&token=xxxxxx'data = '\n'.join(urls)headers = {'Content-Type': 'text/plain'}r = requests.post(api, data=data, headers=headers)print r.text