转义用于创建POST请求的特殊字符

时间:2016-10-31 09:32:29

标签: objective-c nsstring special-characters quickblox nsstringencoding

我正在使用第三方服务Qu​​ickBlox来管理我应用的后端。用户可以在后端输入文本和创建对象。但是,当我向https://api.quickbloc.com/users.json创建POST请求并尝试发送特殊字符时,QuickBlox库会创建一个如下所示的数据对象:

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

但是,QuickBlox会以"should contain alphanumeric and punctuation characters only"

回复

我已尝试手动向QuickBlox发出请求,并发现发布的数据应如下所示:

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

正在使用QuickBlox pod构建请求,它具有以下标题:

[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)"; }

并发送请求参数如下:

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

}

我不确定如何转发正在发送的数据,以免被拒绝。我正在使用IOS Objective C

我正在创建这样的请求:

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


[QBRequest signUp:user successBlock etc etc

我只需要发送一组有限的特殊字符,所以我甚至尝试过这样的黑客尝试让它们通过:

_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:@"\\ú"];

0 个答案:

没有答案