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";
}
?>