Je suis en train d'avoir des tuyaux verticaux dans l'URLURL Objectif C avec tubes/barres verticales
Chaîne d'entrée: http://testURL.com/Control?command=dispatch|HOME|ABC:User Nom
-(NSString *)getURLEncodedString:(NSString *)stringvalue{
NSMutableString *output = [NSMutableString string];
const unsigned char *source = (const unsigned char *)[stringvalue UTF8String];
int sourceLen = strlen((const char *)source);
for (int i = 0; i < sourceLen; ++i) {
const unsigned char thisChar = source[i];
if (thisChar == ':' || thisChar == '/' || thisChar == '?' || thisChar == '=' || thisChar == '|' || thisChar == '.' || thisChar == '-' || thisChar == '_' || thisChar == '~' ||
(thisChar >= 'a' && thisChar <= 'z') ||
(thisChar >= 'A' && thisChar <= 'Z') ||
(thisChar >= '0' && thisChar <= '9')) {
[output appendFormat:@"%c", thisChar];
} else {
[output appendFormat:@"%%%02X", thisChar];
}
}
return output;
}
Chaîne de sortie après avoir appelé méthode ci-dessus: http://testURL.com/Control?command=dispatch|HOME|ABC:User%20Name
maintenant , si je passe la chaîne de codage ci-dessus à [[NSURL URLWithString: encodedString];
Je reçois Domain = NSURLErrorDomain Code = -1000 "mauvaise URL" UserInfo = {0xae9d760 NSUnderlyingError = 0xaec8ed0 "mauvaise URL", NSLocalizedDescription = mauvaise URL}
Toute entrée sur ce gars-là? Je veux que l'URL ressemble à encodedString.
Merci!
Qu'allez-vous en faire? '|' n'est pas un caractère valide dans une URL, c'est pourquoi il est rejeté en tant que mauvaise URL. – gaige
duplication possible de [symbole de conduite verticale non détecté dans NSURL] (http://stackoverflow.com/questions/6167331/vertical-pipe-symbol-not-being-detected-in-nsurl) – Mobilewits