ASP:
Copy codeThe Code is 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> tips for developing websites </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> </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,100 00, 10000,100 00
'The first value: the DNS name resolution timeout time is 10 seconds.
'The second value: the timeout time for establishing a Winsock connection is 10 seconds.
'Third value: the timeout time for sending data is 10 seconds.
'Fourth value: the timeout time for receiving response is 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
'Role: 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 codeThe Code is 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> script home </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 ";
}
?>