I'm currently developing a Rest Resource that will be able to handle post method into Salesforce. The request that I get is in form-data(!!!).
It contains Hebrew characters translated into Unicode (i.e. : \u05E9\u05D5\u05DC\u05DD ==> שולם)
But when I want to get this data:
request.params is a Map<String, String> and I think there is a wrong cast with a wrong encoding at some time
so far I tested these options :
@RestResource(urlMapping='/MeshResponse/*')
global without sharing class MeshResponseHandler {
@HttpPost
global static void handleResponse() {
RestRequest req = RestContext.request;
//All the tests here get the same results
//1rst option
System.debug(req.params.get('data[status]'));
//2nd option (unescapeHtml4)
System.debug(req.params.get('data[status]').unescapeHtml4());
//3rd option (re-serialize everything)
String s1 = JSON.serialize(req);
Map<String,Object> m = (Map<String, Object>) JSON.deserializeUntyped(s1);
Map<String,Object> m2 = (Map<String, Object>) JSON.deserializeUntyped(JSON.serialize(m.get('params')));
String s2 = System.debug((String)m2.get('data[status]'));
}
PS: I don't have any control on the sender side and yes I already checked this REST API Unicode characters not working and since I don't have request body, this doesn't help me at all
---- Edit ---- @DavidReed Could you provide a complete example of a request body?
RestRequest:[headers={Accept=*/*, Accept-Language=en-US,en;q=0.9,he;q=0.8, CipherSuite=ECDHE-RSA-AES256-GCM-SHA384 TLSv1.2 443, Connection=keep-alive, Content-Type=application/x-www-form-urlencoded, Host=partial-bm.cs81.force.com, Origin=https://meshulam.co.il, Sec-Fetch-Dest=empty, Sec-Fetch-Mode=navigate, Sec-Fetch-Site=none, ...}, httpMethod=POST, params={data[allPaymentsNum]=1, data[asmachta]=75954662, data[cardBrandCode]=3, data[cardBrand]=Visa, data[cardExp]=0631, data[cardSuffix]=0000, data[cardTypeCode]=1, data[cardType]=Local, data[description]=, data[firstPaymentSum]=0, ...}, remoteAddress=x.x.x.x, requestBody=Blob[0], requestURI=/MeshResponse, resourcePath=/services/apexrest/MeshResponse/*]
The params has to be something like this :
params={data[allPaymentsNum]=1, data[asmachta]=7595466244, data[cardBrandCode]=3, data[cardBrand]=Visa, data[cardExp]=0631, data[cardSuffix]=0000, data[cardTypeCode]=1, data[cardType]=Local, data[description]=, data[firstPaymentSum]=0, data[status]=\u05E9\u05D5\u05DC\u05DD, data[fullName]=\u05D9\u05E2\u05E7\u05D1 \u05D0\u05DC\u05D1\u05D6 }
The problem is that as you can see, I don't have all the params when I do a Req.tostring(), I tried to serializepretty but I get the same as in the picture above