我在json中发送字典,它有两个数组和多个值,但我得到响应访问被拒绝

我发送两个数组和多个值扔json但是当我发送这个我得到成功代码200和它的响应显示访问被拒绝任何人给我正确的方法来解决它**

-(void)SaveColumnConnection { NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURLURLWithString:@"http://xxxyyyzzzz.php"]]; NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:oneRowColumn,@"oneRowCols",memberTid,@"table_title_id",totalRowStr,@"totRow",rowandColumn,@"tempColName",tableOptIdArray ,@"tempOptid",companyId,@"companyid",@"savecolumniphone",@"tag",nil]; NSLog(@"dict %@",dict); SBJSON *parser =[[SBJSON alloc] init]; NSString *jsonString = [parser stringWithObject:dict]; [request setHTTPMethod:@"POST"]; [request setHTTPBody:[jsonString dataUsingEncoding:NSUTF8StringEncoding]]; [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { NSHTTPURLResponse *HTTPResponse = (NSHTTPURLResponse *)response; NSInteger statusCode = [HTTPResponse statusCode]; if (statusCode==200) { //Request goes in success NSString *str = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; NSLog(@"Json for post array ----------%@",str); } else{ ///request is get failed NSLog(@"Error Description %@",[error localizedDescription]); } }]; [request release]; } 

试试这段代码

 NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:oneRowColumn,@"oneRowCols",memberTid,@"table_title_id",totalRowStr,@"totRow",rowandColumn,@"tempColName",tableOptIdArray ,@"tempOptid",companyId,@"companyid",@"savecolumniphone",@"tag",nil]; NSString *jsonRequest = [dict JSONRepresentation]; NSURL *url = [NSURL URLWithString:@"http://xxxyyyzzzz.php"]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0]; NSData *requestData = [NSData dataWithBytes:[jsonRequest UTF8String] length:[jsonRequest length]]; [request setHTTPMethod:@"POST"]; [request setValue:@"application/json" forHTTPHeaderField:@"Accept"]; [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; [request setValue:[NSString stringWithFormat:@"%d", [requestData length]] forHTTPHeaderField:@"Content-Length"]; [request setHTTPBody: requestData]; connection = [[NSURLConnection alloc]initWithRequest:request delegate:self]; 

想要看看你的PHP代码..不管怎样,请检查以下示例是否可以帮助你…这里我没有发送任何字典值,根据你的要求调整代码:)

 NSString *jsonRequest = @"{\"username\":\"user\",\"password\":\"pwd\"}"; NSLog(@"Request: %@", jsonRequest); NSURL *url = [NSURL URLWithString:@"http://xxxyyyzzzz.php"]; NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url]; NSData *requestData = [NSData dataWithBytes:[jsonRequest UTF8String] length:[jsonRequest length]]; [request setHTTPMethod:@"POST"]; [request setValue:@"application/json" forHTTPHeaderField:@"Accept"]; [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; [request setValue:[NSString stringWithFormat:@"%d", [requestData length]] forHTTPHeaderField:@"Content-Length"]; [request setHTTPBody: requestData]; [NSURLConnection connectionWithRequest:[request autorelease] delegate:self];