我使用代码从以下问题向 wordpress 博客发表评论:
以编程方式从 iPhone 向 WordPress 博客发表评论
我做了一些修改以从 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, address=0x0)。进程已恢复到执行前的状态。
我将不胜感激任何建议来确定这里有什么问题。我使用 XCode 4.5.2 并在装有 iOS 6.0.1 的 iPhone 4S 上运行代码