Reputation: 5011
Encountered a problem on posting comment back to a comment box. post not showing up, there is no error or whatsoever to check.
EDIT: Correct Answer
-(void)postToBoard
{
NSString *post = @"author=Jos&[email protected]&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];
}
Upvotes: 0
Views: 330
Reputation: 41005
This line looks wrong:
[request setValue:@"wp-comments-post.php" forHTTPHeaderField:@"Content-Type"];
It should be:
[request addValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
I'm not sure what you're supposed to do with "wp-comments-post.php", should that perhaps be in the URL instead?
Upvotes: 1