【发布时间】:2018-03-21 20:48:38
【问题描述】:
我尝试在 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;
}
}
它显示了我想要的正确信息。
但是,在服务器端,ua 仍然是 android 和 ios 设备的默认值:
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)
是否可以更改在 react-native 中发送的请求的 user-agent,如果可以?
【问题讨论】:
标签: android react-native fetch