JAVA、PHP、前端、APP、网站开发 - 开发技术学习

开发技术学习 » APP开发 » react-native添加header useragent

react-native添加header useragent

此文被围观2981日期: 2019-12-18 分类 : APP开发  标签:  ····

在React Native应用中我们可以使用WebView来构建Web页面。

传递自定义表头header

配置ReactNative应用程序时请示页面发送自定义请求表头

let customHeaders = {
  "X-DemoApp-Version": "1.1",
  "X-DemoApp-Type": "demo-app-react-native"
}

在调用WebView组件时我们可以调用customHeaders


Android传递user agent


ios传弟user agent,需要修改AppDelegate.m

NSString *newAgent = @"demo-react-native-app";
NSDictionary *dictionary = [[NSDictionary alloc] initWithObjectsAndKeys:newAgent, @"UserAgent", nil];
[[NSUserDefaults standardUserDefaults] registerDefaults:dictionary];


来源:https://blog.bigbinary.com/2016/07/10/passing-user-agent-or-custom-header-in-react-native-webview.html


补充:感觉以上都不好用呢,还是使用这个,将在userAgent后加上以下字符。

applicationNameForUserAgent={'DemoApp/1.1.0'}


站点声明:部分内容源自互联网,为传播信息之用,如有侵权,请联系我们删除。

© Copyright 2011-2024 www.kfju.com. All Rights Reserved.
超级字帖 版权所有。蜀ICP备12031064号