ios - AFNetworking base64 parameter, characters being escaped by NSJSONSerialization -
i attempting submit image cardshark's api using afnetworking.
nsdata *imagedata = uiimagejpegrepresentation(cardimage, 1.0); nsdictionary *parameters = @{@"front" : [imagedata base64encodedstringwithseparatelines:no]}; nsstring *path = [nsstring stringwithformat:@"cardshark?webhookurl=%@&apikey=%@", kcardsharkwebhookurlencodedstring, kcardsharkapikey]; [self postpath:path parameters:parameters success:^(afhttprequestoperation *operation, id responseobject) { completion(responseobject, nil); } failure:^(afhttprequestoperation *operation, nserror *error) { completion(nil, error); }];
i've tried combinations of base64 string.
base64encodedstringwithseparatelines:yes
base64encodedstringwithseparatelines:no
base64encodedstring
to no avail, after inspecting httpbody
on request generated seeing things beingness escaped.
the raw base64 starts /9j/4aaqskzjrgabaqaaaqabaad/4qbyrxhpzgaatu0akgaaaagaagesaamaaaab aaeaaidpaaqaaaabaaaajgaaaaaaa6abaamaaaabaaeaakacaaqaaaabaaaeokad aaqaaaabaaacraaaaad/2wbdaaebaqebaqebaqebaqebaqebaqebaqebaqebaqeb
but 1 time it's gone through afnetworking , presumably nsjsonserialization beingness posted
\/9j\/4aaqskzjrgabaqaaaqabaad\/4qbyrxhpzgaatu0akgaaaagaagesaamaaaabaaeaaidpaaqaaaabaaaajgaaaaaaa6abaamaaaabaaeaakacaaqaaaabaaaeokadaaqaaaabaaacraaaaad\/2wbdaaebaqebaqebaqebaqebaqebaqebaqebaqebaqebaqebaqebaqebaqebaqebaqebaqebaqebaqebaqebaqebaqh\/
as can see /
beingness escaped. how prevent escaping? passing exact json body api via tool (a la, curl) causes api produce error. what's best approach here?
it turns out more of fault of api. afnetworking has next code sets content-type header charset=utf-8
.
case afjsonparameterencoding:; [request setvalue:[nsstring stringwithformat:@"application/json; charset=%@", charset] forhttpheaderfield:@"content-type"]; [request sethttpbody:[nsjsonserialization datawithjsonobject:parameters options:0 error:&error]]; break;
for whatever reason beyond understanding, api did not back upwards charset
attribute on header.
with said, fast prepare issue , working no modification code shown above.
ios json base64 afnetworking nsjsonserialization
No comments:
Post a Comment