I send a few strings to my server which works perfectly fine but for some reason when i try to send a link as an NSString it doesn't send correctly.
For example the NSString PDF_URL variable is equal to:
https://s3.amazonaws.com/the+PDFs/email%40hotmail.ca_product+name+is+something_the+keycode.PDF
In my myRequestString
PDF_URL is formatted correctly. But when I check my email (in my case i send the url to my email) the url ends up like this:
https://s3.amazonaws.com/the PDFs/email@hotmail.ca_product name is something_the keycode.PDF
I have no idea why objective C replaces those character's but it does it while POST to my server because I breakpoint right before it sends to check my variable and its formatted correctly.
my code:
-(void)sendPDFtoEmail{
NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *defaultSession = [NSURLSession sessionWithConfiguration: defaultConfigObject delegate: nil delegateQueue: [NSOperationQueue mainQueue]];
NSURL * url = [NSURL URLWithString:@"my url"];
NSMutableURLRequest * urlRequest = [NSMutableURLRequest requestWithURL:url];
NSString *PDF_URL = [NSString stringWithFormat:@"%@%@%@%@%@%@%@", @"https://s3.amazonaws.com/the+PDFs/", email, @"_", name, @"_", keycode, @".PDF"];
// Create your request string with parameter name as defined in PHP file
NSString *myRequestString = [NSString stringWithFormat:@"name=%@&email=%@&keycode=%@&PDF_URL=%@", Name, email, keycode, PDF_URL];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setHTTPBody:[myRequestString dataUsingEncoding:NSUTF8StringEncoding]];
NSURLSessionDataTask * dataTask =[defaultSession dataTaskWithRequest:urlRequest
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
NSLog(@"Response:%@ %@\n", response, error);
if(error == nil)
{
NSString *response = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];
}
}];
[dataTask resume];
}
Also its not my PHP because i send the same string URL in Android to the same PHP and when i check my email the link isn't formatted.