将此网址转换为base 64

时间:2013-02-12 04:51:21

标签: iphone base64

我试过这种方式,但它没有用。

这是转换为base 64的网址

NSString *strUrlB64 = [NSString stringWithFormat:@"https://play.google.com/store/apps/details?id=com.ShiftSharerfree_new&feature=search_result#?t=W251bGwsMSwyLDEsImNvbS5TGlmdFNoYXJlcmZyZWVfbmV3Il0"];

NSData *dataUrl = [NSData dataFromBase64String:strUrlB64];

然后尝试将其发送到另一个网址。

NSString *urlStr = [NSString stringWithFormat:@"http://server39.pnht.com/360ad/apps/ads/%@/android/136/ord0.910950258132325?json=1&package_url=%@",self.mStrPid, dataUrl];

它给我输出:NSString * urlStr = [NSString stringWithFormat:@“http://server39.pbgs.com/360ads/apps/ad/%@/android/1360/ord0.910950252132325?json=1&package_url=%@”,self.mStrPid,url];

它不是基础64.请指导如何从中获得基础64.

1 个答案:

答案 0 :(得分:1)

我使用base 64编码和解码某些文字,  你可以告诉我它是否适用于网址

- (NSString *)base64Encode:(NSString *)plainText
 {
    NSData *plainTextData = [plainText dataUsingEncoding:NSUTF8StringEncoding];
    NSString *base64String = [plainTextData base64EncodedString];
    return base64String;
 }

- (NSString *)base64Decode:(NSString *)base64String
{
    NSData *plainTextData = [NSData dataFromBase64String:base64String];
    NSString *plainText = [[NSString alloc] initWithData:plainTextData   encoding:NSUTF8StringEncoding];
    return plainText;
}