0

I am loading a webView with an external url and post data.

Everything works fine, unless the data contains the '+' character, then it fails. I've tried to encode the data in differents ways but I can't make it work. How can I correctly encode the plus character?

-(void) cargarWebViewTPVRedys:(TPVRedsys*) redsys{

    NSURL *url = [NSURL URLWithString: @"https://sis-t.redsys.es:25443/sis/realizarPago"]; // PRUEBAS
    // NSURL *url = [NSURL URLWithString: @"https://sis.redsys.es/sis/realizarPago"];     // REAL
    NSString *body = [NSString stringWithFormat: @"DS_SIGNATURE=%@&DS_MERCHANTPARAMETERS=%@&DS_SIGNATUREVERSION=%@",redsys.Ds_Signature,redsys.Ds_MerchantParameters,redsys.Ds_SignatureVersion];
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL: url];
    [request setHTTPMethod: @"POST"];
    //[request setHTTPBody: [body dataUsingEncoding: NSUnicodeStringEncoding]];
    //[request setHTTPBody: [body dataUsingEncoding: NSASCIIStringEncoding]];
    [request setHTTPBody: [body dataUsingEncoding: NSUTF8StringEncoding allowLossyConversion:false]];
    NSLog(redsys.Ds_Signature);
    NSLog(redsys.Ds_MerchantParameters);
    NSLog(redsys.Ds_SignatureVersion);

    [self.webView loadRequest:request];
}
TMob
  • 1,278
  • 1
  • 13
  • 33
D4rWiNS
  • 2,585
  • 5
  • 32
  • 54
  • Can not you use stringbyreplacingoccurrencesofstring? – Awesome.Apple Mar 11 '16 at 11:18
  • The '+' character must arrive at the url, so I cant just remove it – D4rWiNS Mar 11 '16 at 11:19
  • Where is the "+" sign, it is not in the question. – zaph Mar 11 '16 at 11:55
  • in redsys.Ds_Signature ( is a NSString), – D4rWiNS Mar 11 '16 at 13:30
  • Hi D4rWiNS! Is TPVRedsys a class you have developed? or have you downloaded it from some page? I have to use TPV with an iOS app and I'm struggling looking for a redsys library for Objective C. – Wonton Jul 05 '17 at 10:55
  • I developed it myselft – D4rWiNS Jul 05 '17 at 11:36
  • I've asked about my problems making ios payments through Redsys API here in SO: https://stackoverflow.com/questions/44936947/ios-3des-enccryption-for-tpv-payments could you please see what's the problem with my code? – Wonton Jul 05 '17 at 22:28
  • I generate the signature on the server side so I don't know where is your problem at the IOS code, but seems like the problem is in the ds_signature – D4rWiNS Jul 06 '17 at 09:15

1 Answers1

0

Seems that replace the '+' character for Its hexadecimal value

NSString *body = [body2 stringByReplacingOccurrencesOfString:@"+" withString:@"%2B"];
D4rWiNS
  • 2,585
  • 5
  • 32
  • 54