Quote:
Originally Posted by verbatimbot
Hello,
I am trying to get a response from a webservice with simple
Code:
NSString *strData = [NSString stringWithContentsOfURL:url];
but NSUrl never gets initialized - I am appending parameters to mutable string. If I hardcode values with single @"url-with-parameters" everything goes ok.
Must say I'm beginner in obj-c programming.
Code:
NSMutableString *urlString = [[NSMutableString alloc] initWithString:@"http://www.someurl.com/httphandlers/iphonedatastore.ashx?mode=contact"];
[urlString appendString:@"&name="];
[urlString appendString:txtName.text];
[urlString appendString:@"&msg="];
[urlString appendString:txtMessage.text];
[urlString appendString:@"&email="];
[urlString appendString:txtEmail.text];
[urlString appendString:@"&subj="];
[urlString appendString:txtSubject.text];
NSURL *url = [[NSURL alloc] initWithString:urlString];
Thanks in advance
|
I'm pretty sure that the string has to represent a legal URL or the call to initWithString will fail and return nil.
If I had to guess, I would say that some of the text you are using to build your URL contains spaces or other illegal characters.
You are asking for SERIOUS trouble if you pass user-entered text directly into a URL without checking it and escaping special characters.
I don't have time at the moment, but I can dig up code I've used in the past to take user input and escape it for including in a URL.
Remember, characters like "&", "=", "/" "@" and of course space, are all special in a URL and have to be handled differently.