我在本地主机服务器上安装了 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", @"[email protected] /cdn-cgi/l/email-protection", @"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 发表评论?
首先,如果您在 iPhone 上运行的代码中使用“localhost”,那么“localhost”将指代iPhone不发送到您的网络服务器。如果你有一个公共IP,那么把你的服务器的IP放在那里,否则通过WiFi将你的iPhone连接到与你的本地服务器相同的LAN,并使用该服务器的IP(我猜它会像192.168.. .)。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)