<WebView source={{html:'...'}} userAgent={DeviceInfo.getUserAgent()}></WebView>
我使用WebView
向服务器发送请求并设置userAgent
。但是发现服务器收到的user-agent
是okhttp/3.6.0
。那么userAgent
有什么问题?
您发送了DeviceInfo.getUserAgent()
收到的数据,我建议您在userAgent
属性中添加您想要传递给服务器的自定义数据。例如,在WebView中设置自定义数据,它应该在Android版本中按预期工作。
<WebView
source={ {uri: this.props.url} }
userAgent="demo-react-native-app"
/>
最终它不适用于iOS版本,这里AppDelegate.m文件中的几行代码需要它的支持。
NSString *newAgent = @"demo-react-native-app";
NSDictionary *dictionary = [[NSDictionary alloc] initWithObjectsAndKeys:newAgent, @"UserAgent", nil];
[[NSUserDefaults standardUserDefaults] registerDefaults:dictionary];