C# XMLRPC 自定义字段
我试图用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我唯一的猜测是您的参数中存在命名不匹配。我看到的文档说 newPost 结构中的字段应该是
custom_fields
而不是cf
: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 thancf
: