Peut-être que je devrais écrire "Très très très, courts extraits», cependant, est une excellente et pratique "truc" pour montrer ce que je suis. L'exécution de la "deux" lignes de code ci-dessous, vous pouvez obtenir la sortie d'une URL et de le manipuler.
1 2 3 4 5 | url = [ NSString stringWithFormat : @ "http://www.appleside.it/" ] ; NSString * url = [ NSString stringWithFormat: @ "http://www.appleside.it/"]; result = [ NSString stringWithContentsOfURL : [ NSURL URLWithString : url ] NSString * result = [ NSString stringWithContentsOfURL: [ NSURL URLWithString: url] encodage: NSASCIIStringEncoding ] ; erreur: nil]; "Indirizzo: %@ = %@" , url, result ) ; NSLog (@ "Adresse:% @ =% @", url, résultat); |
Par exemple nous pourrions profiter de nombreux services pour résoudre divers problèmes API REST. Juste pour vous donner un exemple concret, imaginons volre "compresser" (trim) le http://www.undolog.com url, comme de nombreux services comme Twitter, FriendFeed ou Facebook. Eh bien nous pourrions utiliser ce code simple:
1 2 3 4 5 6 | url = @ "http://www.undolog.com" ; NSString * url = @ "http://www.undolog.com"; apiRest = [ NSString stringWithFormat : @ "http://api.tr.im/v1/trim_simple?url=%@" ,url ] ; NSString * apiRest = [ NSString stringWithFormat: @ "% @ http://api.tr.im/v1/trim_simple?url =" url]; result = [ NSString stringWithContentsOfURL : [ NSURL URLWithString : apiRest ] NSString * result = [ NSString stringWithContentsOfURL: [ NSURL URLWithString: apiRest] encodage: NSASCIIStringEncoding ] ; erreur: nil]; "URL Originale: %@ - URL Compresso: %@" ,url, result ) ; NSLog (@ "URL d'origine: @% - URL comprimé:% @", url, résultat); |
Tout le crédit, bien sûr, est la méthode stringWithContentsOfURL : car il vous permet de charger le contenu dans une chaîne (de sortie) d'une URL.










Il n'y a aucun commentaire pour cet article
Laisser un commentaire