直接发送Trackback的3组代码
Trackback是什么,自己看 TrackBack – 維基百科。 直接发送Trackback 可以干什么,自己想(不要作恶)。以下分享3种不同语言 直接发送Trackback的代码片断。
3种语言分别是 Python、PHP、ASP.net, 如果你直接运行这些脚本,期望发送至不同的博客,那么你肯定会很失望,这些只是例子,并且不完整; 我也不会把如何搭建可运行环境的过程写出来,请自己Google。
1. PHP版 (运行需要 pear,依赖Services_Trackback, Services_Trackback依赖HTTP_Request2, HTTP_Request2依赖Net_URL2 )
<?php
$trackbackData = array(
'title' => 'Trackback Test',
'excerpt' => 'Where is my frends? ...',
'url' => 'http://mifunny.info/friends',
'blog_name' => 'My Blog',
'trackback_url' => 'http://mifunny.info/how-to-obtain-the-flow-of-foreign-brush-google-adsense-229.html/trackback'
);
// include class
include "Services/Trackback.php";
// initialize new instance
$trackback = new Services_Trackback();
// set object properties
foreach ($trackbackData as $k => $v) {
$trackback->set($k, $v);
}
// send trackback
$ret = $trackback->send();
if (PEAR::isError($ret)) {
echo "ERROR. Trackback failed because: " . $ret->getMessage();
} else {
echo "Trackback successfully posted";
}
?>
2. Python版 (需要 tblib函数库 )
import tblib
tblib.TrackBack()
tb.autodiscover('http://mifunny.info/how-to-obtain-the-flow-of-foreign-brush-google-adsense-229.html/trackback')
print tb.tbUrl
tb.blog_name = 'My Weblog'
tb.title = 'Trackback Test'
tb.url = 'http://mifunny.info/friends'
tb.excerpt = 'Where is my frends? ...'
tb.ping()
print tb.tbErrorCode
3. ASP.net版 (LD不懂ASP,仅仅列出代码)
//// 作 用:向指定的URL发送Trackback Ping,并根据服务器端返回的信息,提示用户处理情况。参数必须Server.URLEncode
///目标URL,也即所引用的blog所提供的引用地址
///我的Blog的URL
///我的blog站点名称
///当前这篇blog的标题
///当前这篇blog的摘要
/// 返回结果:字符串,以“|”分隔,第一部分为数字,0表示成功,1表示有错;第二部分是具体信息。
public static int Send(string RemoteUrl, string MyBlogURL, string MyBlogName, string MyBlogTitle, string MyBlogExcerpt)
{
// 构造要发送的请求内容
try
{
string strPostInfo = “title=” + MyBlogTitle;
strPostInfo += “&url=” + MyBlogURL;
strPostInfo += “&excerpt=” + MyBlogExcerpt;
strPostInfo += “&blog_name=” + MyBlogName;
byte[] strs = System.Text.Encoding.Default.GetBytes(strPostInfo);
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(RemoteUrl);
myRequest.Method = “POST”;
myRequest.ContentType = “application/x-www-form-urlencoded”;
myRequest.ContentLength = strs.Length;
Stream newStream = myRequest.GetRequestStream();
// 发送数据
newStream.Write(strs, 0, strs.Length);
newStream.Close();
return 1;
}
catch (System.Exception es)
{
return 0;
}
}



高手呀 。。。这个我不会用的。。收学费不 嘿嘿
回复
NO.1 Trackback Test by LD …
[...]If you can see this, don’t tell others! My Friends.[...]…
NO.2 Trackback Test by LD…
[...]If you can see this, don’t tell others! GUEST BOOK MA[...]…
LD\’s Notepad…
[...]If you can see this, don\’t tell others! ABOUT MIFUNNY.INFO, ABOUT L[...]…
有时间学习玩玩
回复
真的倒了,python php asp你都会,你真的是在打击我啊。。。。。
回复
LD 回复:
三月 1st, 2009 at 8:50 下午
@小桥流水人家, asp偶不会, py和php也只是浅尝辄止, 毕竟也是要用时才看一下
回复