Application case of Baidu real-time push api interface
Baidu real-time push api interface application case, in view of this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.
Baidu webmaster platform http://zhanzhang.baidu.com/
Open the Baidu webmaster platform and click the add New data API for real-time push to obtain the api push address with token:
Http://ping.baidu.com/sitemap?site=www.yourdomain.com&resource_name=sitemap&access_token=xxxxxxx
Share a piece of php real-time push code written by netizens:
Php pushes newly released articles in real time
Push sitemap in socketopen mode
The copy code is as follows:
Function sitemap_ping_baidu ($urls) {
$baidu_ping_url = 'ping.baidu.com'
$get ='/ sitemap?site=www.yourdomain.com&resource_name=sitemap&access_token=xxxxxxx'
$port=80
If (($io = fsockopen ($baidu_ping_url, $port, $errno, $errstr, 50))! = false) {
$send = "POST $get HTTP/1.1". "rn"
Send. = 'Accept: * / *'. "rn"
$send. = 'Cache-Control: no-cache'. "rn"
$send. = 'Host:'. $baidu_ping_url. "rn"
$send. = 'Pragma: no-cache'. "rn"
/ / $send. = "Referer: http://".$url.$get."rn";
/ / $send. = 'User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)'. "rn"
$xml =''
Foreach ($urls as $url) {
$xml. ='
$xml. ='
$xml. =''.date (' Ymurmmurd').
$xml. = 'monthly'
$xml. = '0.8'
$xml. ='
}
$xml. ='
Send. = 'Content-Length:'.strlen ($xml). "rn"
$send. = "Connection: Closernrn"
$send. = $xml. "rn"
Fputs ($io, $send)
$return =''
While (! Feof ($io))
{
$return. = fread ($io, 4096)
}
Return $return
} else {
Return false
}
}
$return = sitemap_ping_baidu (array ('http://www.yourdomain.com/a.php?id=1'));)
The xml document that Baidu will return after push
The copy code is as follows:
two hundred
The meaning of status code is as follows
200 No usage error. You need to further check whether the returned content is correct. 400 required parameters do not provide a request method that is not supported by POST. We only support POST to submit data. 411HTTP header is missing Content-Length field 413. The data pushed is too large. Exceeding the limit of 10MB, the length of the Content-Length declaration in the 422HTTP header is inconsistent with the actual data length. 500The answer to the question about the application case of Baidu's real-time push api interface is shared here. I hope the above content can be of some help to everyone. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.