[VB.NET] Programming automatic posting of news to Wordpress using XML-RPC

Trong bài viết này, mình xin hướng dẫn các bạn viết ứng dụng tự động đăng tin lên blog Wordpress. Trong tuts này mình sử dụng XML-RPC để post bài từ ứng dụng VB.NET của mình lên trang web.

[VB.NET] Lập trình đăng tin tự động lên Wordpress sử dụng XML-RPC

Đầu tiên, mình xin nói về thằng XML-RPC là gì?

XML-RPC là một cài đặt RPC (Remote Procedure Call) trên nền giao thức HTTP, sử dụng XML để mã hoá và trao đổi dữ liệu.


Giao diện demo của ứng dụng auto post tin lên blog Wordpress:

Bước 1: Các bạn tạo các control và cài đặt thuộc tính cho nó như sau
Textbox 1 : Name : txtTitle
Textbox 2 : Name : txtpost, Multiline : True
Button : Name: btnPost

Bước 2: Tiếp tục chèn thư viện XMLRPC.NET vào solution, các bạn có thể download thư viện về trên trang http://xml-rpc.net.

Bước 3: Chúng ta code cho sự kiện khi click vào button btnPost như sau

+ Code ứng dụng bằng ngôn ngữ lập trình VB.NET

  Imports CookComputing.XmlRpc
 
Public Structure blogInfo
      Public title As String
      Public description As String
End Structure
 
Public Interface IgetCatList
       _
      Function NewPage(ByVal blogId As Integer, ByVal strUserName As String, ByVal strPassword As String, ByVal content As blogInfo, ByVal publish As Integer) As String
End Interface

Dim newBlogPost As blogInfo = Nothing
newBlogPost.title = txtTitle.Text
newBlogPost.description = txtPost.Text
categories = CType(XmlRpcProxyGen.Create(GetType(IgetCatList)), IgetCatList)
clientProtocol = CType(categories, XmlRpcClientProtocol)
clientProtocol.Url = "http://127.0.0.1/wpl/xmlrpc.php"
Dim result As String = Nothing
result = ""
Try
      result = categories.NewPage(1, "shoban", "shoban", newBlogPost, 1)
      MessageBox.Show("Posted to Blog successfullly! Post ID : " & result)
      txtPost.Text = ""
      txtTitle.Text = ""
Catch ex As Exception
      MessageBox.Show(ex.Message)
End Try
+ Sử dụng code  bằng ngôn ngữ C#

using CookComputing.XmlRpc;
 
public struct blogInfo
{
    public string title;
    public string description;
}
 
public interface IgetCatList
{
    [CookComputing.XmlRpc.XmlRpcMethod("metaWeblog.newPost")]
    string NewPage(int blogId, string strUserName,
        string strPassword, blogInfo content, int publish);
}

blogInfo newBlogPost = default(blogInfo);
newBlogPost.title = txtTitle.Text;
newBlogPost.description = txtPost.Text;
categories = (IgetCatList)XmlRpcProxyGen.Create(typeof(IgetCatList));
clientProtocol = (XmlRpcClientProtocol)categories;
clientProtocol.Url = "http://127.0.0.1/wpl/xmlrpc.php";
string result = null;
result = "";
try
{
    result = categories.NewPage(1, "shoban", "shoban", newBlogPost, 1); MessageBox.Show("Posted to Blog successfullly! Post ID : " + result);
    txtPost.Text = "";
    txtTitle.Text = "";
}
catch (Exception ex)
{
    MessageBox.Show(ex.Message);
}
  

Chúc các bạn thành công với thủ thuật trên.

PASSWORD UNZIP: HUNG.PRO.VN
Chúc Mọi Người Thành Công Với Thủ Thuật Trên.
Nếu mọi người có vướng mắc gì mình chia sẽ trên trang có thể gửi liên hê cho mình tại đây nhé.
Cảm ơn mọi người đã quan tâm.

4 comments:

Hung Program VN said...

HIỆN TẠI CHƯƠNG TRÌNH NÀY KHÔNG HOẠT ĐỘNG ĐC NỮA NHÉ MỌI NGƯỜI VÌ K THỂ DOWNLOAD FILE TỪ XML-PRC NỮA. TKS

Trần Sum said...

thanks for share, please help me code auto post any more website for web? tks adm

Hung Program VN said...

what is this website?

Khoa Nguyen said...

trang tải file .dll bị die rồi kìa adm? k có dữ .dll để gọi dữ liệu thì có cách nào khác k?

All Right Reserved © 2015 By Hung Pro VN