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();
};
@dann1609
Copy link

dann1609 commented Jan 5, 2018

Great!!

@halimbimantara
Copy link

great job

@tonyjt
Copy link

tonyjt commented Aug 14, 2018

Great!!

@kwekuayepah
Copy link

Thank you very very much!!!!

@mit4dev
Copy link

mit4dev commented Oct 18, 2018

Thanks!

@dt-martin
Copy link

Thanks, save my day

@arbeeorlar
Copy link

Great, save my day

@duvansh91
Copy link

thanks :)

@ghstahl
Copy link

ghstahl commented Dec 9, 2018

me too 👍

@sumupur
Copy link

sumupur commented Mar 19, 2019

me too
thanks:)

@jeremiahogutu
Copy link

Thank you!

@Vanns35
Copy link

Vanns35 commented Nov 12, 2019

Thank you :)

@afelipen
Copy link

Thank you!

@Raw-Gel
Copy link

Raw-Gel commented Feb 12, 2020

thank you!!!

@ykavi
Copy link

ykavi commented Feb 17, 2020

Thank you ^..^

@Draymonders
Copy link

3q~

@Samranvirk44
Copy link

Its working fine

@naijab
Copy link

naijab commented Jul 27, 2020

Thanks sir. I help my day

@ceemafour
Copy link

you my friend, are a life saviour !!!

@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