URLに垂直パイプを入れようとしています
入力文字列: http://testURL.com/Control?command=dispatch|HOME|ABC :ユーザー名
-(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;
}
上記のメソッドを呼び出した後の出力文字列: http://testURL.com/Control?command=dispatch|HOME|ABC:User%20Name
ここで、上記のエンコード文字列を [[NSURL URLWithString:encodedString]; に渡すと、
Domain=NSURLErrorDomain Code=-1000 "bad URL" UserInfo=0xae9d760 {NSUnderlyingError=0xaec8ed0 "bad URL", NSLocalizedDescription=bad URL} を取得しています
この人たちについて何か意見はありますか?URLをencodedStringのように見せたいです。
ありがとうございました!