以编程方式从iPhone发布对WordPress博客的评论

时间:2012-03-05 09:27:05

标签: iphone wordpress mobile

我在我的localhost服务器上安装了WordPress博客,并制作了一个iPhone应用程序,通过rss浏览博客。我尝试使用此代码以编程方式发布评论。

#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];

我需要在用户未登录时使用此代码。如何实现?

如何从iPhone发表评论?

1 个答案:

答案 0 :(得分:1)

首先,如果您在iPhone上运行的代码中使用“localhost”,那么“localhost”将引用 iPhone 而不是您的Web服务器。把你的服务器的IP放在那里,如果你有一个公共IP而不是那个通过WiFi将你的iPhone连接到与本地服务器相同的局域网并使用该服务器的IP(我猜它会像192.168那样.. )。

相关问题