Saturday, 31 August 2013

Issue with HTTP POST request iOS

Issue with HTTP POST request iOS

So I have gathered this code to send a POST request to a web service
however I keep getting this error
*** Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: '*** +[NSString
stringWithUTF8String:]: NULL cString'
and I have looked to see what it means but do not understand responses in
the context of this code.
Any help greatly appreciated, thanks
-(IBAction)buttonPressed:(id)sender{
NSString *myRequestString = @"idvar=76";
NSData *myRequestData = [ NSData dataWithBytes: [ myRequestString
UTF8String ] length: [ myRequestString length ] ];
NSMutableURLRequest *request = [ [ NSMutableURLRequest alloc ]
initWithURL: [ NSURL URLWithString: @"192.168.0.11/test/deleteerrand.php"
] ];
[ request setHTTPMethod: @"POST" ];
[ request setValue:@"application/x-www-form-urlencoded"
forHTTPHeaderField:@"content-type"];
[ request setHTTPBody: myRequestData ];
NSURLResponse *response;
NSError *err;
NSData *returnData = [ NSURLConnection sendSynchronousRequest: request
returningResponse:&response error:&err];
NSString *content = [NSString stringWithUTF8String:[returnData bytes]];
NSLog(@"responseData: %@", content);
}

No comments:

Post a Comment