用asp與php實現(xiàn)百度ping服務(wù)的代碼
更新時間:2012年02月04日 14:13:54 作者:
分別用asp與php實現(xiàn)百度ping服務(wù)的代碼,需要的朋友可以參考下
ASP:
<%
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>開發(fā)網(wǎng)站的一些小技巧</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>發(fā)送Ping到:" & Url & "</p>"
Response.Flush
Dim objPing
Set objPing = Server.CreateObject("MSXML2.ServerXMLHTTP")
objPing.SetTimeOuts 10000, 10000, 10000, 10000
‘第一個數(shù)值:解析DNS名字的超時時間10秒
‘第二個數(shù)值:建立Winsock連接的超時時間10秒
‘第三個數(shù)值:發(fā)送數(shù)據(jù)的超時時間10秒
‘第四個數(shù)值:接收response的超時時間10秒
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
‘===============================================
‘函數(shù)名:BytesToBstr
‘作用:字符集轉(zhuǎn)換
‘參數(shù):body–內(nèi)容;Cset–指定的字符集
‘===============================================
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:
<?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>腳本之家</string></value></param>
<param><value><string>http://www.dbjr.com.cn</string></value></param>
<param><value><string>http://www.dbjr.com.cn/a/15222.html</string></value></param>
<param><value><string>http://www.dbjr.com.cn</string></value></param>
</params>
</methodCall>";
$res = postUrl(‘http://ping.baidu.com/ping/RPC2′, $baiduXML);
if ( strpos($res, "<int>0</int>") )
{
echo "PING成功";
}
else
{
echo "PING失敗";
}
?>
復(fù)制代碼 代碼如下:
<%
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>開發(fā)網(wǎng)站的一些小技巧</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>發(fā)送Ping到:" & Url & "</p>"
Response.Flush
Dim objPing
Set objPing = Server.CreateObject("MSXML2.ServerXMLHTTP")
objPing.SetTimeOuts 10000, 10000, 10000, 10000
‘第一個數(shù)值:解析DNS名字的超時時間10秒
‘第二個數(shù)值:建立Winsock連接的超時時間10秒
‘第三個數(shù)值:發(fā)送數(shù)據(jù)的超時時間10秒
‘第四個數(shù)值:接收response的超時時間10秒
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
‘===============================================
‘函數(shù)名:BytesToBstr
‘作用:字符集轉(zhuǎn)換
‘參數(shù):body–內(nèi)容;Cset–指定的字符集
‘===============================================
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:
復(fù)制代碼 代碼如下:
<?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>腳本之家</string></value></param>
<param><value><string>http://www.dbjr.com.cn</string></value></param>
<param><value><string>http://www.dbjr.com.cn/a/15222.html</string></value></param>
<param><value><string>http://www.dbjr.com.cn</string></value></param>
</params>
</methodCall>";
$res = postUrl(‘http://ping.baidu.com/ping/RPC2′, $baiduXML);
if ( strpos($res, "<int>0</int>") )
{
echo "PING成功";
}
else
{
echo "PING失敗";
}
?>
相關(guān)文章
win10 + anaconda3 + python3.6 安裝tensorflow + keras的步驟詳解
這篇文章主要介紹了win10 + anaconda3 + python3.6 安裝tensorflow + keras的步驟,需要的朋友可以參考下2019-09-09基于ChatGPT使用AI實現(xiàn)自然對話的原理分析
ChatGPT是當(dāng)前自然語言處理領(lǐng)域的重要進(jìn)展之一,可以生成高質(zhì)量的文本,可應(yīng)用于多種場景,如智能客服、聊天機(jī)器人、語音助手等。本文將詳細(xì)介紹ChatGPT的原理、實戰(zhàn)演練和流程圖,幫助讀者更好地理解ChatGPT技術(shù)的應(yīng)用和優(yōu)勢2023-05-05Runnable.com 在線測試代碼片分享網(wǎng)站
Runnable是一個一站式的代碼片段集合網(wǎng)站,你不僅可以搜索代碼,還可以編輯、運(yùn)行這些代碼片段,以確保它們的正確性與可用性2013-12-12vim中tagbar配置以及打字時隱藏鼠標(biāo)的方法
這篇文章主要給大家介紹了關(guān)于vim中tagbar配置以及打字時隱藏鼠標(biāo)的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-11-11ffmpeg安裝及音頻轉(zhuǎn)換指令應(yīng)用
ffmpeg是一套可以用來記錄、轉(zhuǎn)換數(shù)字音頻、視頻,本文主要介紹了ffmpeg安裝及音頻轉(zhuǎn)換指令應(yīng)用,具有一定的參考價值,感興趣的可以了解一下2024-02-02