NSMutableURLRequest and a Password with special Characters won't work
- by twickl
I'm writing a small program (using Cocoa Touch), which communicates with a webservice.
The code for calling the webservice, is the following:
- (IBAction)send:(id)sender
{
if ([number.text length] > 0)
{
[[UIApplication sharedApplication] beginIgnoringInteractionEvents];
[activityIndicator startAnimating];
NSString *modded;
modded = [self computeNumber];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL: [NSURL URLWithString:@"https://tester:%=&[email protected]/RPC2"]];
[theRequest setHTTPMethod:@"POST"];
[theRequest addValue:@"text/xml" forHTTPHeaderField:@"content-type"];
[theRequest setCachePolicy:NSURLCacheStorageNotAllowed];
[theRequest setTimeoutInterval:5.0];
NSString* pStr = [[NSString alloc] initWithFormat:@"<?xml version=\"1.0\" encoding=\"UTF-8\"?><methodCall><methodName>samurai.SessionInitiate</methodName><params><param><value><struct><member><name>LocalUri</name><value><string></string></value></member><member><name>RemoteUri</name><value><string>sip:%@@sipgate.net</string></value></member><member><name>TOS</name><value><string>text</string></value></member><member><name>Content</name><value><string>%@</string></value></member><member><name>Schedule</name><value><string></string></value></member></struct></value></param></params></methodCall>", modded, TextView.text];
NSData* pBody = [pStr dataUsingEncoding:NSUTF8StringEncoding];
[theRequest setHTTPBody:pBody];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if (!theConnection)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
message:@"A Connection could not be established!"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles: nil];
[alert show];
[alert release];
sendButton.enabled = TRUE;
return;
}
[pStr release];
[pBody release];
}
}
The Username and Password have to be in the URL, and it works in most cases, but when the password consists of special characters like in the example "%=&=-Test2009", the Webservice does not respond. If it is something like "Test2009" it works fine. Does anyone have an idea why, and maybe a solution for that?