Search code examples
phpioshyperlinknewlinensurl

NSURL with \n to call a php file


I'm using the following line of code to run my php file that I have on my server. the issue is that the \n causes an error and disables the php file from getting called. but when i remove the \n it works.

  NSString *link = [[NSString alloc]initWithFormat:@"%@?message=%@",link,[@"hello   world\nhello" stringByReplacingOccurrencesOfString:@" " withString:@"%20"]];
  NSData *resultData = [NSData dataWithContentsOfURL:[NSURL URLWithString:link]];

I don't know what to do to make this work. is there anything else that i need to use instead of \n?!

thanks


Solution

  • try this:

    NSString *link = [[NSString alloc]initWithFormat:@"%@?message=%@",link,@"hello   world\nhello"];
    NSString *url = [link stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
    NSData *resultData = [NSData dataWithContentsOfURL:[NSURL URLWithString:url]];