0
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];
        }

我是目标 c 的新手。当我发送带有参数的 NSURL 时,它会给出错误,因为“参数太多需要 1 有 2”如何用一个参数更改我的 url?

4

2 回答 2

2

代替

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

NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://nyxmyx.com/Kinkey/KinkeyPHP/lastid2.php/?data=%@",myString]];
于 2013-02-18T05:05:59.097 回答
1

我已经纠正了一些事情并测试了您的代码,现在应该没问题:

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,80808080,1360738531881.jpg
,808080,1360708080 ,null,+ 6142022444442.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,是的







于 2013-02-18T06:14:24.043 回答