图片使用ikaca。
CSDN论坛提供了一套API,我们通过这套API来实现一个简单的发帖工具。

关于API的使用方法,可以参见下面的文章:怎样利用CSDN论坛公开的API实现自己的论坛工具http://community.csdn.net/openapi/openapiexplain.htm。
API是通过WebService提供的,下面以C#为例子,说明如何使用WebService。创建一个C#的工程,在“解决方案资源管理器”中的“引用”处,单击鼠标右键,选择“添加服务引用”,弹出如下的对话框,

在“地址”中填入http://forum.csdn.net/OpenApi/forumapi.asmx,单击“前往”按钮,VS解析该地址中提供的服务,如图中所示,找到1个服务,我们可以修改命名空间为CSDNForumAPI。
点击确定按钮后便完成服务引用的添加。

首先,我们获得要发帖的论坛的ID,通过GetForums方法获得,该方法没有传入参数,返回一个论坛的列表,以Forum结构数组保存。
CSDNForumAPI.ForumAPISoapClient ForumAPIService = new PostHelper.CSDNForumAPI.ForumAPISoapClient();
Forum[] Forums = ForumAPIService.GetForums();
foreach (Forum f in Forums)
{
Console.WriteLine(f.name);
Console.WriteLine(f.forumId);
}
保存论坛的ID用于发帖时填充Post结构的forumId成员。 根据API说明,发帖方法如下:
/// <summary>
        /// 发帖
        /// </summary>
        /// <param name="identity">用户身份证</param>
        /// <param name="post">帖子</param>
        /// <param name="error">错误信息</param>
        /// <param name="topicUrl">帖子链接</param>
        /// <returns>发帖是否成 功</returns>
        public bool Post(Identity identity, Post post, out Error error, out string topicUrl)
为了调用Post方法,我们需要Identity和Post对象,Identity保存了发帖账号和密码。Post则为帖子结构。
Identity identity = new Identity();
identity.username = username;
identity.password = password; Post topic = new Post();
topic.body = body;
topic.editor = type;
topic.expertUserName = expertName;
topic.forumId = forumId;
topic.isAskExpert = askExpert;
topic.point = point;
topic.subject = subject;
topic.tag = "";
topic.url = ""; Error error = new Error();
try
{
bool ret = ForumAPIService.Post(out error, out topicUrl, identity, topic);

return ret;
}
catch(System.Exception)
{
//error
}


jingzhongrong