0

I'm using a third party service QuickBlox to manage a backend of my app. Users can input text and create objects on the backend. However, when I create a POST request to https://api.quickbloc.com/users.json and attempt to send special characters the QuickBlox library creates a data object that looks like this:

user =     {
    login = "\U00e1\U00e9\U00ed\U00f3\U00fa";
    password = ssssddddd;
};

However, QuickBlox then responds with "should contain alphanumeric and punctuation characters only"

I have tried make the request manually to QuickBlox and have discovered that the data being posted should look like this:

{"user": { "login":"\\U00c1\\U00e1\\U00e9\\U00ed\\U00f3\\U00fa", "password":"sdddddddd" } }

The request is being constructed using QuickBlox pod and it has the following headers:

[QBCore] Request headers: { "Accept-Language" = "ga;q=1, en-GB;q=0.9, en;q=0.8"; "Content-Type" = "application/x-www-form-urlencoded"; "QB-OS" = "iOS 8.4"; "QB-SDK" = "iOS 2.7.2"; "QB-Token" = xxxxxx; "QuickBlox-REST-API-Version" = "0.1.1"; "User-Agent" = "tomhais/1.0 (iPhone; iOS 8.4; Scale/2.00)"; }

and send the request parameters as follows:

{
user =     {
    login = "\U00e1\U00e9\U00ed\U00f3\U00fa";
    password = ssssddddd;
};

}

I'm unsure how to escape the data being sent so that it isn't rejected. I'm using IOS Objective C

I'm creating the Request like this:

QBUUser *user = [QBUUser new];
user.password = password;
user.login = userName; // where userName is an NSSTRING


[QBRequest signUp:user successBlock etc etc

It's only a limited set of special characters that I need to send so I even tried a hack like this to try get them through:

_ainmInput.text = [_ainmInput.text stringByReplacingOccurrencesOfString:@"Á" withString:@"\\Á"]; _ainmInput.text = [_ainmInput.text stringByReplacingOccurrencesOfString:@"á" withString:@"\\á"]; _ainmInput.text = [_ainmInput.text stringByReplacingOccurrencesOfString:@"É" withString:@"\\É"]; _ainmInput.text = [_ainmInput.text stringByReplacingOccurrencesOfString:@"é" withString:@"\\é"]; _ainmInput.text = [_ainmInput.text stringByReplacingOccurrencesOfString:@"Í" withString:@"\\Í"]; _ainmInput.text = [_ainmInput.text stringByReplacingOccurrencesOfString:@"í" withString:@"\\í"]; _ainmInput.text = [_ainmInput.text stringByReplacingOccurrencesOfString:@"Ó" withString:@"\\Ó"]; _ainmInput.text = [_ainmInput.text stringByReplacingOccurrencesOfString:@"ó" withString:@"\\ó"]; _ainmInput.text = [_ainmInput.text stringByReplacingOccurrencesOfString:@"Ú" withString:@"\\Ú"]; _ainmInput.text = [_ainmInput.text stringByReplacingOccurrencesOfString:@"ú" withString:@"\\ú"];

Léo Natan
  • 56,823
  • 9
  • 150
  • 195
Linda Keating
  • 2,215
  • 7
  • 31
  • 63
  • You already indicated that you are using Objective C in your tags; there is no need to add it to the title. – Léo Natan Oct 31 '16 at 09:33
  • @Linda - Try this for special characters request parameter NSData *loginData = [login dataUsingEncoding:NSNonLossyASCIIStringEncoding]; NSString *comment = [[NSString alloc] initWithData:loginData encoding:NSUTF8StringEncoding]; – kaushal Oct 31 '16 at 10:07
  • Hi @kaushal that definitely brings me a step closer : but now the data being sent is `login = "\\301\\351\\355\\363\\372 ";` and not the unicode chars – Linda Keating Oct 31 '16 at 10:20
  • @Linda : It should be nearly double to your input unicode characters, and \U will not display as I have changed it to NSUTF8StringEncoding now your server has to handle it is UTF8 character set. while getting response from server, you will got UTF8 string. – kaushal Oct 31 '16 at 10:39
  • To convert it back to objective c string : NSData *nsdataFromBase64String = [responseString dataUsingEncoding:NSUTF8StringEncoding]; NSString *loginUser = [[NSString alloc]initWithData:nsdataFromBase64String encoding:NSNonLossyASCIIStringEncoding]; – kaushal Oct 31 '16 at 10:43

0 Answers0