Webview用户代理无法在本机中工作

问题描述 投票:2回答:1
<WebView source={{html:'...'}} userAgent={DeviceInfo.getUserAgent()}></WebView>

我使用WebView向服务器发送请求并设置userAgent。但是发现服务器收到的user-agentokhttp/3.6.0。那么userAgent有什么问题?

react-native webview user-agent
1个回答
0
投票

您发送了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];
© www.soinside.com 2019 - 2024. All rights reserved.