Data uploaden
Hoi,
Ik probeer data te uploaden in m'n database, met de volgende code:
Code:
-(IBAction)update{
NSString *post = @"key1=val1&key2=val2";
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://www.marvinvdgraaff.nl/onsys/test.php?naam=%@",[userName text]]]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSURLConnection *conn=[[NSURLConnection alloc] initWithRequest:request delegate:self];
if (conn)
{
NSLog(@"Gelukt!");
}
else
{
// inform the user that the download could not be made
NSLog(@"Mislukt!!");
}
}
[userName text] is dus het textfield dat ik verzonden wil hebben, maar nu krijg ik dus in m'n database een leeg veld aan, dus wat doe ik fout?
moet ik niets veranderen aan: NSString *post = @"key1=val1&key2=val2"; ??
Alvast bedankt,
Tim!
|