C# XMLRPC 自定义字段

发布于 2024-12-15 11:38:35 字数 1758 浏览 0 评论 0原文

我试图用 C# 编写一个程序,但我陷入了困境。该程序假设通过 xmlrpc 在 wordpress 上创建一个帖子。我可以成功创建帖子,但在为帖子创建自定义字段时遇到问题。因此,当我打开创建的帖子时,自定义字段永远不存在。我希望你们中的一些大师可以帮助我,因为我现在被困了 3 天,不知道该怎么做,感到绝对无助:(

这是一些代码:

public struct customField
        {
            public string key;
            public string value; 
        }
        public struct newPost
        {
            public string[] categories;
            public string title;
            public string description;
            public string mt_excerpt;
            public customField[] cf;
        }
public interface IcreatePost
       {
           [CookComputing.XmlRpc.XmlRpcMethod("metaWeblog.newPost")]
           string NewPost(int blogId, string strUserName,
               string strPassword, newPost content, int publish);
       }

这是我如何为名为的对象

    customField newCustomField2 = default(customField);

    newCustomField2.key = "some data";

    newCustomField2.value = "some data";


    newPost newBlogPost = default(newPost);
    newBlogPost.title = "Some Title";
    newBlogPost.description = "Some Content";
    newBlogPost.cf = new customField[] { newCustomField2 };
createPost(newBlogPost);

函数设置值的方法:

public void createPost(newPost np)
        {

            string postid;
            icp = (IcreatePost)XmlRpcProxyGen.Create(typeof(IcreatePost));
            clientProtocol = (XmlRpcClientProtocol)icp;
            clientProtocol.Url = "http://127.0.0.1/xmlrpc.php";
            try
            {
                postid = icp.NewPost(1, "admin", "1234", np, 1); 

            }
            catch (Exception ex)
            {
                MessageBox.Show("createPost ERROR ->"+ ex.Message);
            }
        }

Im trying to to write a program in C# and I'm stuck. The program suppose to create a post on wordpress via xmlrpc. I can create the post successfully but I have problems creating custom fields for the post. So when I open created post, custom fields are never there. I hope some of you gurus can help me as I am stuck for 3 days now and cant figure out what to do, feel absolutely helpless:(

Heres some code:

public struct customField
        {
            public string key;
            public string value; 
        }
        public struct newPost
        {
            public string[] categories;
            public string title;
            public string description;
            public string mt_excerpt;
            public customField[] cf;
        }
public interface IcreatePost
       {
           [CookComputing.XmlRpc.XmlRpcMethod("metaWeblog.newPost")]
           string NewPost(int blogId, string strUserName,
               string strPassword, newPost content, int publish);
       }

Heres how I set values for the object

    customField newCustomField2 = default(customField);

    newCustomField2.key = "some data";

    newCustomField2.value = "some data";


    newPost newBlogPost = default(newPost);
    newBlogPost.title = "Some Title";
    newBlogPost.description = "Some Content";
    newBlogPost.cf = new customField[] { newCustomField2 };
createPost(newBlogPost);

Function called:

public void createPost(newPost np)
        {

            string postid;
            icp = (IcreatePost)XmlRpcProxyGen.Create(typeof(IcreatePost));
            clientProtocol = (XmlRpcClientProtocol)icp;
            clientProtocol.Url = "http://127.0.0.1/xmlrpc.php";
            try
            {
                postid = icp.NewPost(1, "admin", "1234", np, 1); 

            }
            catch (Exception ex)
            {
                MessageBox.Show("createPost ERROR ->"+ ex.Message);
            }
        }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

奈何桥上唱咆哮 2024-12-22 11:38:35

我唯一的猜测是您的参数中存在命名不匹配。我看到的文档说 newPost 结构中的字段应该是 custom_fields 而不是 cf

public struct newPost
{
    public string[] categories;
    public string title;
    public string description;
    public string mt_excerpt;
    public customField[] custom_fields;
}

My only guess here would be that there is a naming mismatch in your parameters. The documentation that I've seen says that the field inside the newPost struct should be custom_fields rather than cf:

public struct newPost
{
    public string[] categories;
    public string title;
    public string description;
    public string mt_excerpt;
    public customField[] custom_fields;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文