所以我收集了这段代码来向Web服务发送POST请求,但是我一直收到此错误
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** +[NSString stringWithUTF8String:]: NULL cString'
我已经看过它的含义,但是在这段代码的上下文中却没有理解答案。
非常感谢任何帮助,谢谢
-(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);
}
答案 0 :(得分:0)
试试这个
NSString *content = [[NSString alloc] initWithData: returnData encoding:NSASCIIStringEncoding];