how to convert Nsurl Domain to my country domain
Example :
NSURL *url = [NSURL URLWithString:#"http://www.google.com"];
How can get some thing like http://www.google.com.eg
it can detect my zone and change it with my domain zone, if website support multi zones domain.
If there isn't a path in the url just append .eg to the end of the string.
NSString *newCountryString = [[url absoluteString] stringByAppendingString:#".eg"];
NSURL *newCountryUrl = [NSURL URLWithString:newCountryString];
If the url has a path do this:
NSString *host = [url host];
NSString *domain = [[host componentsSeparatedByString:#"."] lastObject];
NSString *newCountryString = [[url absoluteString] stringByReplacingOccurrencesOfString:domain withString:[domain stringByAppendingString:#".eg"]];
NSURL *newCountryUrl = [NSURL URLWithString:newCountryString];
Related
The endpoint does not care if the URL has spaces in it, but NSURL seems to.
I get nil for NSURL *url = [NSURL URLWithString:string]; every time:
NSString *string = [NSString stringWithFormat:#"http://endpoint.com/search?one=%#&two=%#", textField1.text, textField2.text];
NSURL *url = [NSURL URLWithString:string];
NSString *urlAbsolute = [url absoluteString];
[theManager GET:urlAbsolute parameters:nil progress:nil success:^(NSURLSessionTask * _Nonnull task, id _Nullable responseObject) {
I want to pass spaces into the endpoint because I want to get spaces out of the endpoint. (i.e. pass "Star Wars" in, so I get "Star Wars" back out instead of "StarWars" if I removed spaces from the string).
Any ideas?
Use the string encoding with allowed characters
Please find the below code.
NSString *string = [NSString stringWithFormat:#"http://endpoint.com/search?one=%#&two=%#", textField1.text, textField2.text];
NSURL *url = [NSURL URLWithString:[string stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]]];
Try this code :
NSString *firstArgument = [self.textField1.text stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]];
NSString *secondArgument = [self.textField2.text stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]];
NSString *string = [NSString stringWithFormat:#"http://endpoint.com/search?one=%#&two=%#", firstArgument, secondArgument];
NSURL *url = [NSURL URLWithString:string];
NSString *urlAbsolute = [url absoluteString];
I have a URL which is in a string: http://bs.serving-sys.com/BurstingPipe/adServer.bs?cn=is&c=23&pl=VAST&pli=10226041&PluID=0&pos=6670&ord=%5B1423164382.84%5D&cim=1
I am trying to convert that string to NSURL.
I've tried several things, which are:
NSString *encodedString = [#"http://bs.serving-sys.com/BurstingPipe/adServer.bs?cn=is&c=23&pl=VAST&pli=10226041&PluID=0&pos=6670&ord=%5B1423164382.84%5D&cim=1" stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
NSURL *url = [NSURL URLWithString:encodedString];
When I follow the URL object with a breakpoint it assigns 0 => false.
What should I do to convert that string to NSURL?
The parameters in your given URL string are already URL encoded. So:
NSString *string = #"http://bs.serving-sys.com/BurstingPipe/adServer.bs?cn=is&c=23&pl=VAST&pli=10226041&PluID=0&pos=6670&ord=%5B1423164382.84%5D&cim=1";
NSURL *url = [NSURL URLWithString:string];
// url is not nil
i am NewBie in iOS Development. I want to Decode my NSURL With Pagination Here my Url Like as
http://www.janvajevu.com/webservice/categorylist.php?category=%E0%AA%B8%E0%AB%8D%E0%AA%B5%E0%AA%BE%E0%AA%B8%E0%AB%8D%E0%AA%A5%E0%AA%AF&page=0
And i Decode this URL Like as
NSURL *urls = [NSURL URLWithString:#"http://www.janvajevu.com/webservice/categorylist.php?category=%E0%AA%B8%E0%AB%8D%E0%AA%B5%E0%AA%BE%E0%AA%B8%E0%AB%8D%E0%AA%A5%E0%AA%AF&page=0"];
NSString *urlString = [urls absoluteString];
NSLog(#"UrlString %#",urlString);
NSURL * url=[NSURL URLWithString:urlString];
But it Give me Only 0 Page Url i want to Like as make my url as
NSURL *urls=[NSURL URLWithString:#"My Url &page=%d",pagenum];
Here i want at place of My Url as Decoding of my Original Url If it is Possible then Please Give me Solution for it.
you are doing it in wrong way.
this is the right way
NSString *urlString = #"http://www.janvajevu.com/webservice/categorylist.php?category=%E0%AA%B8%E0%AB%8D%E0%AA%B5%E0%AA%BE%E0%AA%B8%E0%AB%8D%E0%AA%A5%E0%AA%AF&page=";
NSURL *targetURL = [NSURL URLWithString:[NSString stringWithFormat:#"%#%d",urlString,pageNumber]];
NSLog(#"targetURL is : %#",targetURL);
Hope this will help you..
NSString *str=#"http://www.janvajevu.com/webservice/categorylist.php?category=%E0%AA%B8%E0%AB%8D%E0%AA%B5%E0%AA%BE%E0%AA%B8%E0%AB%8D%E0%AA%A5%E0%AA%AF&page=0";
NSString *result =[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *urls = [NSURL URLWithString:result] ;
I need to use a NSURL object to reach different ressources on the same host.
Here is what I do:
#define MY_HOST #"my.server.eu"
NSURL *url = [[NSURL alloc] initWithScheme:#"http" host:MY_HOST path:#"/"];
Now I need to deal with
http://my.server.eu/path1
http://my.server.eu/path2
http://my.server.eu/path3
How can I modify the path of my NSURL object ?
Why can't we simply do url.path = #"path1" ?
How can I modify the path of my NSURL object ?
Why can't we simply do url.path = #"path1" ?
Because NSURL is an immutable object, and you can't change its properties afterwards. NSMutableURL does not exist, but is on the wish list of many.
In order to achieve what you're after, you're going to have to make 3 separate NSURL objects I'm afraid. To do so, you can convenience the paths within an array:
NSString *host = #"http://my.server.eu/";
NSArray *paths = #[#"path1", #"path2", #"path3"];
NSURL *path1 = [NSURL URLWithString:[NSString stringWithFormat:#"%#%#", host, path[0]]];
NSURL *path2 = [NSURL URLWithString:[NSString stringWithFormat:#"%#%#", host, path[1]]];
NSURL *path3 = [NSURL URLWithString:[NSString stringWithFormat:#"%#%#", host, path[2]]];
You should make the base URL as you're doing and then build the others relative to it using +[NSURL URLWithString:relativeToURL:].
Any ideas how I can get the root of a website from an NSString or an NSURL? So if my URL was http://www.foo.com/bar/baragain how would I get http://www.foo.com/?
By using [url scheme] and [url host] like so:
NSURL *url = [NSURL URLWithString:#"http://www.foo.com/bar/baragain"];
NSLog(#"Base url: %#://%#", [url scheme], [url host]);
// output is http://www.foo.com
NSURL *url = [NSURL URLWithString:#"http://www.foo.com/bar/baragain"];
NSURL *root = [NSURL URLWithString:#"/" relativeToURL:url];
NSLog(#"root = '%#'", root.absoluteString); // root = 'http://www.foo.com/'
You can remove the NSURL's path from the string. This accounts for port numbers and other data that are part of the root site.
NSString *urlString = #"http://www.foo.com/bar/baragain";
NSURL *rootUrl = [NSURL URLWithString:urlString];
NSString *rootUrlString = [urlString stringByReplacingOccurrencesOfString:rootUrl.path withString:#""];
NSString *str = #"http://www.foo.com/bar/baragain";
NSArray *temp = [str componentsSeparatedByString: #".com"];
str = [NSString stringWithFormat: #"%#%#", [temp objectAtIndex:0], #".com"];