Skip to content

Instantly share code, notes, and snippets.

@milon87
Created August 24, 2017 09:27
Show Gist options
  • Save milon87/109c9263821c0c4bac959ce1b4c3357c to your computer and use it in GitHub Desktop.
Save milon87/109c9263821c0c4bac959ce1b4c3357c to your computer and use it in GitHub Desktop.
x-www-form-urlencoded post in react native
getLoginAPI = () => {
let details = {
'username': 'username',
'password': 'demo'
};
let formBody = [];
for (let property in details) {
let encodedKey = encodeURIComponent(property);
let encodedValue = encodeURIComponent(details[property]);
formBody.push(encodedKey + "=" + encodedValue);
}
formBody = formBody.join("&");
fetch('url', {
method: 'POST',
headers: {
'Authorization': 'Bearer token',
'Content-Type': 'application/x-www-form-urlencoded'
},
body: formBody
}).then((response) => response.json())
.then((responseData) => {
console.log(responseData);
AlertIOS.alert(
"POST Response",
"Response Body " + JSON.stringify(responseData.role)
);
})
.done();
};
@Ambikapathi
Copy link

Your are great..!

@huy312100
Copy link

Thanks a lot. You're my hero

@singhdilip1007
Copy link

singhdilip1007 commented Dec 27, 2021

You're great..!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment