I have tried to change the user agent in react native fetch API:
const URLENCODED_HEADER = {
'Accept': 'application/json',
'Content-Type': 'application/json',
'User-Agent': Platform.OS + "/" + DeviceInfo.getUniqueID().toString()
}
export async function doRegister(secureInfo) {
formBody = encodeParameters(secureInfo)
try {
let response = await fetch(SERVER_URL+'/user/register', {
method: "POST",
headers: URLENCODED_HEADER,
body: formBody,
credentials: 'include'
});
let responseJson = await response.json();
return responseJson;
} catch(error) {
console.error(error);
throw error;
}
}
I have also checked the requests' header in Reactotron:
And it shows the correct information I want.
However, on the server side, the ua
is still the default for android and ios devices:
Mozilla/5.0 (iPad; CPU OS 11_2_6 like Mac OS X) AppleWebKit/604.5.6 (KHTML, like Gecko) Version/11.0 Mobile/15D100 Safari/604.1
okhttp/3.6.0
Dalvik/2.1.0 (Linux; U; Android 5.1.1; Coolpad 3622A Build/LMY47V)
Is it possible to change the user-agent
for requests sent in react-native and how if so?
Try to Stop Remote JS Debug
to test it.
I was dealing with the same problem too. It worked for me. :)
Some notes:
<PROJECT_NAME>/<VERSION> CFNetwork/975.0.3 Darwin/17.7.0
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With