IOS Xcode NSURL too many arguments

In my code, I am trying to send some data to a PHP file

To add material to my SQL, I use the GET method.

So far, I needed to use a form on a website, but I would like to add data just by viewing it, for example:

http://server.com/add.php?user=some data here & message = latest data here

I am trying to use this code so far:

NSURL *add = [NSURL URLWithString:@"http://server.com/ios/add.php?user=iPhone App&message=%@", messageBox.text]; [messageView loadRequest:[NSURLRequest requestWithURL:add]]; 

However, Xcode tells me: "Too many arguments to invoke the method expected 1 have 2"

+4
source share
3 answers

try it

 NSString *urlString = @"http://server.com/ios/add.php?user=iPhone App&message="; NSString *escapedString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; NSURL *add = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@",escapedString, messageBox.text]]; [messageView loadRequest:[NSURLRequest requestWithURL:add]]; 

You should use NSString +stringWithFormat:

+1
source

URLWithString accepts strings or string literals. So you should do this:

 NSString* urlString = [NSString stringWithFormat:@"http://server.com/ios/add.php?user=iPhone App&message=%@", messageBox.text]; NSURL *add = [NSURL URLWithString:urlString]; [messageView loadRequest:[NSURLRequest requestWithURL:add]]; 
0
source
 NSURL *add = [NSURL URLWithString:[NSString stringWithFormat:@"http://server.com/ios/add.php?user=iPhone App&message=%@", messageBox.text]]; 

This is because URLWithString: expects only one argument of type NSString *. Use the NSString + stringWithFormat: method to create an NSString object from a formatted string and arguments.

0
source

Source: https://habr.com/ru/post/1440536/


All Articles