Created
August 24, 2017 09:27
-
-
Save milon87/109c9263821c0c4bac959ce1b4c3357c to your computer and use it in GitHub Desktop.
x-www-form-urlencoded post in react native
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
}; |
Thanks, save my day
Great, save my day
thanks :)
me too 👍
me too
thanks:)
Thank you!
Thank you :)
Thank you!
thank you!!!
Thank you ^..^
3q~
Its working fine
Thanks sir. I help my day
you my friend, are a life saviour !!!
Your are great..!
Thanks a lot. You're my hero
You're great..!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks!