DaffodilGirl 2013-02-22 05:41 采纳率: 0%
浏览 5097
已采纳

NSURL带有一个参数传递

NSString *myString = @"1994";
    NSString *post =[[NSString alloc] initWithFormat:@"data=%@",myString];

    NSURL *url=[NSURL URLWithString:@"http://nyxmyx.com/Kinkey/KinkeyPHP/lastid2.php/?data=%@",myString];
    NSLog(@"URL%@",url);

    NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
    NSLog(@"postDATA%@",postData);
    NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
    NSLog(@"postLENGTH%@",postLength);
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];

    [request setURL:url];
    [request setHTTPMethod:@"POST"];
    [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
    [request setHTTPBody:postData];

    NSError *error1 = [[NSError alloc] init];
    NSHTTPURLResponse *response = nil;
    NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error1];
    NSString *string;
    if ([response statusCode] >=200 && [response statusCode] <300)
        {
        string = [[NSString alloc] initWithData:urlData encoding:NSMacOSRomanStringEncoding];
        UIAlertView *alert1=[[UIAlertView alloc]initWithTitle:@"alert1" message:string delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
        [alert1 show];
        }

用上面代码传递带有一个参数的NSURL时就会报错:

Too many arguments expects 1 have 2

不知道该怎么解决?谢谢

  • 写回答

2条回答 默认 最新

  • love_loveec 2013-02-22 07:38
    关注

    我改了一下你的代码,应该没问题了:

    NSString *myString = @"1994";
    NSString *post =[[NSString alloc] initWithFormat:@"data=%@",myString];
    
    NSURL *url=[NSURL URLWithString:[NSString stringWithFormat:@"http://nyxmyx.com/Kinkey/KinkeyPHP/lastid2.php/?data=%@",myString]];
    NSLog(@"URL%@",url);
    
    NSData *postData = [post dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
    NSLog(@"postDATA%@",postData);
    NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
    NSLog(@"postLENGTH%@",postLength);
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
    
    [request setURL:url];
    [request setHTTPMethod:@"POST"];
    [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
    [request setHTTPBody:postData];
    
    NSError *error1 = [[NSError alloc] init];
    NSHTTPURLResponse *response = nil;
    NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error1];
    NSString *string;
    if ([response statusCode] >=200 && [response statusCode] <300)
        {
        string = [[NSString alloc] initWithData:urlData encoding:NSMacOSRomanStringEncoding];
        UIAlertView *alert1=[[UIAlertView alloc]initWithTitle:@"alert1" message:string delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
        [alert1 show];
        }
    

    得到的回应:

    1995,prabu,1231231233,antab,8080808080,1360738531881.jpg,No
    1996,prabu,1231231233,antab,8080808080,1361013972284.jpg,No
    1997,prabu,1231231233,antab,8080808080,1360844505212.jpg,No
    1998,josh,0417697070,null,+61420224346,1361160944442.jpg,No
    1999,josh,0417697070,null,+61420224346,1356047464383.jpg,No
    2000,josh,0417697070,null,+61420224346,1361160816141.jpg,No
    2001,wooza,0420224346,J Wratt ,+61417697070,2013-55-1803-55-54.jpg,No
    2002,wooza,0420224346,J Wratt ,+61417697070,2013-56-1803-56-17.jpg,No
    2003,testing,9894698946,ggh hjj,9894598945,2013-11-1811-11-40.jpg,Yes

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘