views:

188

answers:

2

Hi,

NSString *post = @"&username=adam&password=test";
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
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);

This is my url http://ws.myurl.com/svc-public/iPhoneAuthenticate.aspx, now I need to append the username and password dynamically.

How to append querystring in url? Please help me.

+1  A: 

You can do it this way:

[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://ws.myurl.com/svc-public/iPhoneAuthenticate.aspx?uname=%@&pword=%@",name, password]]];
Vladimir
Of course you'd want to encode your username and password before passing outside your app...
Stephen Darlington
Yes, sure. But that's another question
Vladimir
A: 

This way is fine ...But unfortunately i am getting error

GNU gdb 6.3.50-20050815 (Apple version gdb-966) (Tue Mar 10 02:43:13 UTC 2009) Copyright 2004 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "i386-apple-darwin".sharedlibrary apply-load-rules all Attaching to process 453. (gdb) continue Program received signal: “EXC_BAD_ACCESS”. (gdb)

vinman
Chuck