Post comment to WordPress Blog from iPhone programmatically

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?

Read More

How can I post comment from iPhone?

Related posts

Leave a Reply

1 comment

  1. 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…).