iPhone ASIHttpRequest - can't POST variables asynchronously

Posted by Eamorr on Stack Overflow See other posts from Stack Overflow or by Eamorr
Published on 2011-02-14T23:02:30Z Indexed on 2011/02/14 23:25 UTC
Read the original article Hit count: 371

Greetings,

I'm trying to simply POST data to a url using ASIHttpRequest.

Here is my code:

__block ASIHTTPRequest *request=[ASIHTTPRequest requestWithURL:url];
[request setPostBody:[NSMutableData dataWithData:[@"uname=Hello" dataUsingEncoding:NSUTF8StringEncoding]]];
[request setDelegate:self];
[request setCompletionBlock:^{
    NSString *response=[request responseString];

    UIAlertView *msg=[[UIAlertView alloc] initWithTitle:@"Response" message:response delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [msg show];
    [msg release];
}];
[request setFailedBlock:^{
    NSError *error =[request error];
}];
[request startAsynchronous];

Basically, my url is xxx.xxx.xxx.xxx/login.php, when I dump the PHP $_POST variable, I just get an empty array - i.e. no POST parameters are sent! The rest of the PHP is tested and working fine.

I've looked through the allseeing-i.com documentation and examples and can't seem to resolve this problem.

Any insight greatly appreciated.

Many thanks in advance,

© Stack Overflow or respective owner

Related posts about iphone

Related posts about cocoa-touch