以编程方式从iPhone向WordPress博客发布评论 [英] Post comment to WordPress Blog from iPhone programmatically

查看:70
本文介绍了以编程方式从iPhone向WordPress博客发布评论的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在本地主机服务器上安装了WordPress博客,还制作了一个iPhone应用程序以通过rss浏览该博客.我试图使用此代码以编程方式发布评论.

I installed the WordPress blog on my localhost server and also made an iPhone app to browse the blog via rss. I tried to post a comment programmatically using this code.

#define post_url @"http://localhost/web-wp/wp-comments-post.php"
#define post_content @"comment_post_ID=%@&comment_parent=%@&author=%@&email=%@&comment=%@"

NSString *post_str = [NSString stringWithFormat:post_content, @"1", @"0", @"Viet", @"vietnt88@gmail.com", @"test. comment written on mobile"];
NSData *data = [post_str dataUsingEncoding:NSUTF8StringEncoding];

NSURL * url = [NSURL URLWithString:post_url];
NSMutableURLRequest *req = [[NSMutableURLRequest alloc] initWithURL:url];
[req setHTTPMethod:@"POST"];
[req setHTTPBody:data];

NSURLResponse *response;
NSError *err;
[NSURLConnection sendSynchronousRequest:req returningResponse:&response error:&err];

当用户未登录时,我需要此代码才能工作.如何实现?

I need this code to work when the user is not logged in. How do I achieve that?

如何从iPhone发布评论?

How can I post comment from iPhone?

推荐答案

首先,如果您在iPhone上运行的代码中使用"localhost",则"localhost"将引用 iPhone 不访问您的Web服务器.如果您拥有一个公用IP,则将服务器的IP放在那儿,否则将通过WiFi将iPhone连接到与本地服务器相同的LAN并使用该服务器的IP(我想这将是192.168.. ).

First of all, if you use "localhost" from your code running on your iPhone, then "localhost" will refer to the iPhone not to your web server. Put there the IP of your server, if you have a public IP than that one otherwise connect your iPhone via WiFi to the same LAN as your local server and use the IP of that server (I guess it'll be something like 192.168...).

这篇关于以编程方式从iPhone向WordPress博客发布评论的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆