从 iPhone 应用程序向 Wordpress 博客发表评论

Posted

技术标签:

【中文标题】从 iPhone 应用程序向 Wordpress 博客发表评论【英文标题】:Post comment to Wordpress blog from iPhone App 【发布时间】:2012-11-10 20:09:53 【问题描述】:

我使用代码从以下问题向 wordpress 博客发表评论:

Post comment to WordPress Blog from iPhone programmatically

我做了一些修改以从 UITextFields 获取文本:

- (IBAction)postComment:(id)sender 
    NSString *post_url = @"http://movilarena.com/wp-comments-post.php";
    NSString *post_content = @"comment_post_ID=%@&comment_parent=%@&author=%@&email=%@&comment=%@";

    NSString *post_str = [NSString stringWithFormat:post_content, @"1", @"0", self.txtName.text, self.txtEmail.text, self.txtComment.text];
    NSData *data = [NSData dataWithBytes:[post_str UTF8String] length:[post_str length]];

    NSURL * url = [NSURL URLWithString:post_url];
    NSMutableURLRequest *req = [[NSMutableURLRequest alloc] initWithURL:url];
    [req setHTTPMethod:@"POST"];
    [req setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"content-type"];
    [req setHTTPBody:data];

    //Synchronous
    NSURLResponse *response;
    NSError *err;
    NSData *ret = [NSURLConnection sendSynchronousRequest:req returningResponse:&response error:&err];

    NSString *retString = [NSString stringWithUTF8String:[ret bytes]];
    NSLog(@"%@",retString);

我的问题是 sendSynchronousRequest 返回错误:

执行被中断,原因:EXC_BAD_ACCESS (code=1, 地址=0x0)。进程已经恢复到之前的状态 执行。

我将不胜感激任何建议,以确定这里有什么问题。我使用 XCode 4.5.2 并在装有 ios 6.0.1 的 iPhone 4S 上运行代码

【问题讨论】:

我尝试使用您的代码并收到此错误“抱歉,无法发布此评论。”你能帮我吗 你看到我自己的答案了吗? 【参考方案1】:

自己解决了。 comment_post_ID 字段应该是我要回复的帖子的 ID。

NSString *post_content = @"comment_post_ID=%d&comment_parent=%@&author=%@&email=%@&comment=%@";

NSString *post_str = [NSString stringWithFormat:post_content, self.postID, @"0", self.txtName.text, self.txtEmail.text, self.txtComment.text];

【讨论】:

以上是关于从 iPhone 应用程序向 Wordpress 博客发表评论的主要内容,如果未能解决你的问题,请参考以下文章

当 Apple Watch 处于后台状态或睡眠模式时,我们如何从 iphone 向 Apple Watch 发送消息?

通过 iPhone 在 Wordpress 网站上注册的响应

从 wordpress 触发 laravel 事件

如何使用 Wordpress REST api 从 Vuejs 向 Contact-Form-7 发送消息?

如何使用Xilisoft iPad Magic Platinum for Mac从/向 iPad/iPod/iPhone 传输文件?

WordPress 从哪里获得夏令时信息