c# XMLRPC自定义字段
本文关键字:字段 自定义 XMLRPC | 更新日期: 2023-09-27 18:14:45
我试着用c#写一个程序,我卡住了。该程序假定通过xmlrpc在wordpress上创建一篇文章。我可以成功创建后,但我有问题创建自定义字段的职位。所以当我打开created post时,自定义字段永远不会出现。我希望你们中的一些大师可以帮助我,因为我现在被困了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);
}
}
我唯一的猜测是参数的命名不匹配。我看到的文档说newPost结构体中的字段应该是custom_fields
而不是cf
:
public struct newPost
{
public string[] categories;
public string title;
public string description;
public string mt_excerpt;
public customField[] custom_fields;
}