Как добавить строку запроса в URL, используя цель c? - PullRequest
0 голосов
/ 12 октября 2009

NSString * post = @ "& username = adam & password = test"; NSData * postData = [post dataUsingEncoding: NSASCIIStringEncoding allowLossyConversion: YES]; NSString * postLength = [NSString stringWithFormat: @ "% d", [длина postData]]; NSMutableURLRequest * request = [[[NSMutableURLRequest alloc] init] autorelease];

[request setURL:[NSURL URLWithString:@"http://ws.myurl.com/svc-public/iPhoneAuthenticate.aspx?uname=adam&pword=test"]];

[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSData *returnData = [ NSURLConnection sendSynchronousRequest: request returningResponse: nil error: nil ];
NSString *response = [[NSString alloc] initWithData:returnData encoding:NSASCIIStringEncoding];
NSLog(response);

Это мой URL http://ws.myurl.com/svc-public/iPhoneAuthenticate.aspx, Теперь мне нужно добавить имя пользователя и пароль динамически.

Как добавить строку запроса в URL? Пожалуйста, помогите мне.

1 Ответ

2 голосов
/ 12 октября 2009

Вы можете сделать это так:

[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://ws.myurl.com/svc-public/iPhoneAuthenticate.aspx?uname=%@&pword=%@",name, password]]];
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...