post - React Native - Interact with API - Special Characters Causing Issues - What's the best way to do this? -
i cannot consistently send form variables may/may not include special characters e.g. ? & #
depending on try escape chars encounter different errors when reading data server-side.
i aware update due react native 0.7 include formdata wondered if safely post objects without needing this.
someone has posted similar issue no example code posted illustrate post working: how post form using fetch in react native?
i have tried - amongst other things :
fetch(apiurl, { method: 'post', body: json.stringify({ object1: { param1a: "value 1a", param1b: "value 1b - bad chars & # ?", }, object2: { param2a: "value 2a", param2b: 0, } }) }) but groups data single unnamed parameter (changing api accept not option).
also this:
fetch(apiurl, { method: 'get', accesspackage: json.stringify({ accesstoken: "abc123", tokentype: 2, }), taggdata: json.stringify({ title: "test", wishlistid: 0, anothervar: "anotherval" }) }) i wish receive data 2 strings can parsed json objects @ other end.
looking @ the fetch repo https://github.com/github/fetch hasn't helped assumes post full json post (which isn't) or uses formdata isn't available react native yet.
another solution may safely encode/serialise of data url parameters has proven inconsistent far # char.
what's best way this?
"it groups data single unnamed parameter (changing api accept not option)."
it would, because you've set post body. how it's supposed work.
i wish receive data 2 strings can parsed json objects @ other end.
you can whatever want, there's no magic happening here. receive single string, string set body to. likewise, post body can contain shouldn't confused "special" characters. server-side causing problems.
if want use formdata think it'll in v0.7.0 should out day now, or include js file in own project. can find it here. usage examples in uiexplorer demo.
Comments
Post a Comment