0

我尝试过这种方式,但它不起作用。

这是要转换为 base 64 的 url

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];

它不是base 64。请指导如何从中获取base 64。

4

1 回答 1

1

我正在使用 base 64 编码和解码一些文本,你能告诉我它是否适用于URL

- (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;
}
于 2013-02-12T05:22:08.003 回答