public bool authenticate(string username, string password) { ResultInfo result = new ResultInfo(); // metablog = new JoeBlogs.MetaWeblogWrapper() metablog = new JoeBlogs.MetaWeblogWrapper ("http://upload.move.blog.sina.com.cn/blog_rebuild/blog/xmlrpc.php", username, password); JoeBlogs.Post post = new JoeBlogs.Post(); post.Title = "This is a Test Blog"; post.Body = "this is a test body"; // post.DateCreated = new DateTime(); // try // { //利用异常处理 查看出错信息 string postid = metablog.NewPost(post, true); user = username; passwd = password; return true; /* result.result = true; } catch (Exception ex) { MessageBox.Show("发布日志失败 " + ex.Message); result.message = ex.Message; result.result = false; } return result;*/ }
public void editPost(string postid, string title, string body) { HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument(); doc.LoadHtml(body); HtmlAgilityPack.HtmlNodeCollection nodes = doc.DocumentNode.SelectNodes("//img"); if (nodes != null) foreach (HtmlAgilityPack.HtmlNode node in nodes) { //获取html源地址 HtmlAgilityPack.HtmlAttribute attr = node.Attributes["src"]; JoeBlogs.MediaObject mediaObj = new JoeBlogs.MediaObject(); mediaObj.Name = "test"; mediaObj.Type = "image/jpeg"; FileStream file = new FileStream(attr.Value, FileMode.Open); long size = file.Length; byte[] stream = new byte[size]; file.Read(stream, 0, (int)size); file.Close(); mediaObj.Bits = stream; JoeBlogs.MediaObjectInfo mediainfo = metablog.NewMediaObject(mediaObj); attr.Value = mediainfo.Url; } JoeBlogs.Post post = new JoeBlogs.Post(); post.Title = title; StringWriter writer = new StringWriter(); if (nodes != null) { doc.Save(writer); post.Body = writer.ToString(); } else { post.Body = body; } metablog.EditPost(postid, post, true); }
/*** * 0. wordpress.com站点 http://your_account.wordpress.com/xmlrpc.php 1. 博客园cnblogs http://www.cnblogs.com/your_account/services/metaweblog.aspx 2. 新浪博客 http://upload.move.blog.sina.com.cn/blog_rebuild/blog/xmlrpc.php 3. 网易博客 http://os.blog.163.com/api/xmlrpc/metaweblog/ 4. 自建Wordpress站点 http://your_blog_server/xmlrpc.php 5. 自建zBlog站点 http://your.zblog.site/xml-rpc/index.asp */ private void publishbtn_Click(object sender, EventArgs e) { JoeBlogs.MetaWeblogWrapper metablog = new JoeBlogs.MetaWeblogWrapper ("http://upload.move.blog.sina.com.cn/blog_rebuild/blog/xmlrpc.php", "*****@*****.**", "123456"); JoeBlogs.Post post = new JoeBlogs.Post(); // post.title = "2013"; post.Title = "2013"; try { metablog.NewPost(post, true); } catch (Exception ex) { MessageBox.Show("发布日志失败 " + ex.Message); } }