react native 与服务器交互坑
来源:互联网 发布:知乎 法国街头 编辑:程序博客网 时间:2024/06/05 04:26
今天遇到两个坑
一个是以表单formData封装的JSON格式数据不是标准的json格式,导致服务器解析数据是错误返回400 bad request。例如
let formData = new FormData(); formData.append("api_account", 'iphone'); formData.append("timestamp", (new Date()).valueOf()); formData.append("username","user"); formData.append("password",'1111'); console.log("sent数据:" + JSON.stringify(formData));sent数据:{"_parts":[["api_account","iphone"],["timestamp",1512961607281],["username","user"],["password","1111"]]}
后来改了一种方式可以了
let formdata= JSON.stringify({ "api_account": "iphone", "timestamp": (new Date()).valueOf(), "username": 'user', "password": '1111', }); console.log("==JSON==:" + formdata);
二是iOS模拟器10.3版本访问http协议有限制,
据说引入了新特性App Transport Security (ATS)
。详情:App Transport Security (ATS)
新特性要求App内访问的网络必须使用HTTPS
协议。
但是现在公司的项目使用的是HTTP
协议,使用私有加密方式保证数据安全。现在也不能马上改成HTTPS
协议传输。
NSAppTransportSecurity
类型Dictionary
。2、在
NSAppTransportSecurity
下添加NSAllowsArbitraryLoads
类型Boolean
,值设为YES
3、iOS10以后版本的童鞋,注意了:NSAppTransportSecurity下不要有其他的key,否则NSAllowsArbitraryLoads会被忽略的.
In iOS 10 and later, and macOS 10.12 and later, the value of this key is ignored if any of the following keys are present in your app’s Info.plist file:NSAllowsArbitraryLoadsInMediaNSAllowsArbitraryLoadsInWebContentNSAllowsLocalNetworking
https://developer.apple.com/library/content/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html#//apple_ref/doc/uid/TP40009251-SW60
新手不懂道路深,摸索半天
阅读全文
0 0
- react native 与服务器交互坑
- React Native 与 原生交互
- React Native 与 原生交互
- (十一)React Native---与原生交互
- 对Native 与 React 交互的学习
- React Native与Android通信交互
- react native 与原生之间的交互
- React-Native 与IOS集成交互
- React Native与WebView的交互
- React native和native交互
- React 与服务器交互流程笔记
- 【REACT NATIVE 系列教程之十二】REACT NATIVE(JS/ES)与IOS(OBJECT-C)交互通信
- react与native异步交互的几种方式
- REACT NATIVE(JS/ES)与IOS(OBJECT-C)交互通信
- React Native与Android原生通信交互详情
- React Native与Android原生通信交互详情
- react-native手势及与java端交互应用
- React Native与原生的图片交互问题
- 假设你有一个随机的队列列表。 每个人用一对整数(h,k)来描述,其中h是人的身高,k是身高大于或等于h的人前面的人数。 编写一个算法来重建队列。
- 基于docker搭建oracle服务器
- hibernate配置自动生成表失败 解决办法
- android接入京东开普勒
- python语音朗读
- react native 与服务器交互坑
- 几个美国娱乐业公司
- sqlplus 显示上一条命令及可用退格键
- chrome表单自动填充去掉input黄色背景解决方案
- 【Scikit-Learn 中文文档】处理文本数据
- Spring源码追踪1——doGetBean(为什么org.springframework.data.redis.core.RedisTemplate的实例可以注入为ListOperations)
- C语言中的free函数
- LeetCode刷题 | 738. Monotone Increasing Digits
- java语言实现单链表