With the ASP and PHP to achieve Baidu Ping Service Code _ other comprehensive

Source: Internet
Author: User
Tags dns names
Asp:
Copy Code code as follows:

<%
Option Explicit
Response.Buffer = True
Response.ContentType = "Text/html"
Response.Charset = "Gb2312″
Dim Url, result
URL = "Http://ping.baidu.com/ping/RPC2"
result = Bytestobstr (sendping (URL), "Gb2312″")
IF Instr (result, "<int>0</int>") > 0 Then
Response.Write ("Success")
Else
Response.Write ("Failure")
End IF
Function sendping (URL)
Dim s:s = ""
Randomize ()
Dim r:r = Int (Rnd () * 9999) + 1000
s = S & "<?xml version=" "1.0″" encoding= "Gb2312″"?> "
s = S & "<methodCall>"
s = S & "<methodName>weblogUpdates.ping</methodName>"
s = S & "<params>"
s = S & "<param><value><string> development website Tips </string></value></param>"
s = S & "<param><value><string>http://hi.baidu.com/subendong/blog</string></value ></param> "
s = S & "<param><value><string>http://hi.baidu.com/subendong/blog/item/ 6cd9468d243e8c07b21bba5e.html</string></value></param> "
s = S & "<param><value><string></string></value></param>"
s = S & "</params>"
s = S & "</methodCall>"
Response.Write "<p> Send ping to:" & Url & "</p>"
Response.Flush
Dim objping
Set objping = Server.CreateObject ("MSXML2. ServerXMLHTTP ")
Objping.settimeouts 10000, 10000, 10000, 10000
' First value: timeout 10 seconds to resolve DNS names
' Second value: 10 seconds to set timeout for Winsock connection
' Third value: Timeout time for sending data 10 seconds
' Fourth value: Receive response timeout time 10 seconds
Objping.open "POST", Url & "? r=" & R, False
Objping.setrequestheader "Content-type", "Text/xml"; Charset=gb2312″
Objping.send (s)
sendping = Objping.responsebody
Set objping = Nothing
End Function
' ===============================================
' Function name: bytestobstr
' Function: Character set conversion
' Parameter: body– content; cset– specified character set
' ===============================================
Function bytestobstr (body, Cset)
Dim objstream
Set objstream = Server.CreateObject ("ADODB.stream")
Objstream. Type = 1
Objstream. Mode =3
Objstream. Open
Objstream. Write body
Objstream. Position = 0
Objstream. Type = 2
Objstream. Charset = Cset
Bytestobstr = objstream. ReadText
Objstream. Close
Set objstream = Nothing
End Function
%>

Php:
Copy Code code as follows:

<?php
function PostURL ($url, $postvar)
{
$ch = Curl_init ();
$headers = Array (
"POST". $url. " Http/1.0″,
"Content-type:text/xml; Charset=\ "Gb2312\" ",
"Accept:text/xml",
"Content-length:". strlen ($postvar)
);
curl_setopt ($ch, Curlopt_url, $url);
curl_setopt ($ch, curlopt_returntransfer,1);
curl_setopt ($ch, Curlopt_post, 1);
curl_setopt ($ch, Curlopt_httpheader, $headers);
curl_setopt ($ch, Curlopt_postfields, $postvar);
$res = curl_exec ($ch);
Curl_close ($ch);
return $res;
}
$baiduXML = "<?xml version=\" 1.0\ "encoding=\" gb2312\ "?>"
<methodCall>
<methodName>weblogUpdates.extendedPing</methodName>
<params>
<param><value><string> Cloud-dwelling community </string></value></param>
<param><value><string>http://www.jb51.net</string></value></param>
<param><value><string>http://www.jb51.net/a/15222.html</string></value></ Param>
<param><value><string>http://www.jb51.net</string></value></param>
</params>
</methodCall> ";
$res = PostURL (' http://ping.baidu.com/ping/rpc2′, $baiduXML);
if (Strpos ($res, "<int>0</int>"))
{
echo "Ping successful";
}
Else
{
echo "Ping failed";
}
?>
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.