I'm creating an NSURL
to send as a request to a PHP
rest API
that I've got setup. Here's my code below:
NSMutableString *url = [NSMutableString stringWithFormat:@"http://www.private.com/recievedata.php?item=%@&contact=%@&discovery=%@&summary=%@",__item,__contactDetails,__lostFound,__explain];
//The " ' " in PHP is a special character, so we have to escape it in the URL
//The two slashes are because the "\" itself is a special character in Objective C
NSString *formattedURL = [url stringByReplacingOccurrencesOfString:@"'" withString:@"\\'"];
NSURLSession *session = [NSURLSession sharedSession];
NSURL *address = [NSURL URLWithString:formattedURL];
For some reason though, the address variable holds nil
whenever I try to make the following url happen:
http://www.private.com/recievedata.php?item=hell\'&contact=hell&discovery=lost&summary=hell
I had to add "\" in front of the apostrophes as is evident from my code because PHP needs to have the " ' " escaped in its URLs. But by doing so, it seems like I've violated some requirement set out for NSURL
. What do you guys think?