将评论发回评论框时遇到问题。 邮件没有显示,没有错误或无论如何检查。
编辑:正确答案
-(void)postToBoard
{
NSString *post = @"author=Jos&email=mail@domain.com.au&url=&comment=score+99.&submit=Post+Comment&comment_post_ID=1&comment_post_ID=1&comment_parent=0";
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSString *URLString = @"http://site.com.au/?p=1";
NSURL *postURL = [NSURL URLWithString:URLString];
[request setURL:postURL];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
//[request setValue:@"wp-comments-post.php" forHTTPHeaderField:@"HTTP/1.1"];
[request setHTTPBody:postData];
//self.receivedData = [NSMutableData data];
self.postConnection = [NSURLConnection connectionWithRequest:request delegate:self];
}
答案 0 :(得分:1)
这一行看起来不对:
[request setValue:@"wp-comments-post.php" forHTTPHeaderField:@"Content-Type"];
应该是:
[request addValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
我不确定你应该用“wp-comments-post.php”做什么,或许它应该在URL中呢?