ReactNative http网络通讯
安装 fetch
npm install whatwg-fetch --save
1.fetch的Get方式通讯
async sendGet(){
let response = await fetch('http://192.168.1.138:3000/aa.html');
if(response.ok){
let text = await response.text();
Alert.alert(text);
}
}
render() {
return (
<View style={[Layout.top,{flexDirection:'row',justifyContent:'center',alignItems:'center'}]}>
<Button
onPress={this.sendGet}
title="http请求"
color="#841584"
/>
</View>
)
}
2.fetch的post方式通讯
async sendPost(){
var fetchOptions = {
method: 'POST',
headers: {
'Accept': 'application/json',
//表单
'Content-Type': 'application/x-www-form-urlencoded'
},
body:'email=aaaaaaa&pwd=bbbbbbbbb'
};
let response = await fetch('http://192.168.1.138:3000/shop/aa',fetchOptions);
let text = await response.text();
Alert.alert(text);
}
render() {
return (
<View style={[Layout.top,{flexDirection:'row',justifyContent:'center',alignItems:'center'}]}>
<Button
onPress={this.sendPost}
title="http请求"
color="#841584"
/>
</View>
)
}
3.fetch的二进制post提交
async sendBinaryPost(){
var formData = new FormData();
formData.append('email','aa');
formData.append('pwd','bb');
let response = await fetch('http://192.168.1.138:3000/shop/login',{
method:'POST',
headers:{},
body:formData
});
let text = await response.text();
alert(text);
}
render() {
return (
<View style={[Layout.top,{flexDirection:'row',justifyContent:'center',alignItems:'center'}]}>
<Button
onPress={this.sendBinaryPost}
title="http请求"
color="#841584"
/>
</View>
)
}
ReactNative http网络通讯的更多相关文章
- dicom网络通讯入门(3)
接下来可以进行消息传递了 ,也就是dimse ,再来复习下 什么是dimse .n-set n-create c-echo 这些都是dimse 他们都是属于一种结构的pdu 那就是tf-pdu(传 ...
- dicom网络通讯入门(2)
第二篇,前面都是闲扯 其实正文现在才开始,这次是把压箱底的东西都拿出来了. 首先我们今天要干的事是实现一个echo响应测试工具 也就是echo 的scu,不是实现打印作业管理么.同学我告诉你还早着呢. ...
- 《连载 | 物联网框架ServerSuperIO教程》-4.如开发一套设备驱动,同时支持串口和网络通讯。附:将来支持Windows 10 IOT
1.C#跨平台物联网通讯框架ServerSuperIO(SSIO)介绍 <连载 | 物联网框架ServerSuperIO教程>1.4种通讯模式机制. <连载 | 物联网框架Serve ...
- Windows 网络通讯开发
Windows 网络通讯开发 一.Windows网络开发API 由于C++标准库中没有网络库,所以进行网络开发的时候要调用系统API.Windows通讯开发API包括以下几个基本函数及成员类型: 1. ...
- 文档:网络通讯包结构(crc校验,加解密)
一直想把这个流程整理一下. 包结构: 包 对(datacrc+protoID+dataSize)组成的byte[] 进行crc计算而得到 对(数据内容)进行crc计算而得到 协议号 数据内容的字节长度 ...
- 网络--三种网络通讯方式及Android的网络通讯机制
Android平台有三种网络接口可以使用,他们分别是:java.net.*(标准Java接口).Org.apache接口和Android.net.*(Android网络接口).下面分别介绍这些接口的功 ...
- DIOCP网络通讯流程
DIOCP 运作核心探密 原文连接: http://blog.qdac.cc/?p=2362 原作者: BB 天地弦的DIOCP早已经广为人知了,有很多的同学都用上了它,甚至各种变异.修改版本也出 ...
- Socket网络通讯开发总结之:Java 与 C进行Socket通讯 + [备忘] Java和C之间的通讯
Socket网络通讯开发总结之:Java 与 C进行Socket通讯 http://blog.sina.com.cn/s/blog_55934df80100i55l.html (2010-04-08 ...
- 如何在Windows系统上用抓包软件Wireshark截获iPhone等网络通讯数据
http://www.jb51.net/os/windows/189090.html 今天给大家介绍一种如何在Windows操作系统上使用著名的抓包工具软件Wireshark来截获iPhone.iPa ...
随机推荐
- eclipse部署和启动guns
eclipse部署guns: 1.import -> 搜索maven -> Existing Maven Projects -> 选择guns根目录 2.修改配置文件: spring ...
- Python - 批量改变文件名
import osimport sysimport datetime path = "E:\python_test"datename = '2016-02-11'a = datet ...
- MQTT 在 mac 上搭建
http://blog.csdn.net/YAJUN0601/article/details/41981399 MQTT is a machine-to-machine (M2M)/"Int ...
- Rational Rose 2003 下载、破解及安装方法(图文)
方法一: 1. 安装Rational Rose2003时,在需选择安装项的时候,只选择Rational Rose EnterPrise Edition即可,不需选择其他项,之后选择“DeskTop I ...
- ICE的Glacier2使用
1.使用Glacier2的步骤: A.编写一个Glacier2的配置文件,参见样例 B.设置Glacier2的访问鉴权(密码或者证书),passwords文件每行样例"test xx ...
- Java 利用Gson将json字符串转换为List<Map<String, String>>
json字符串类似于: [ { "userPhone": "123", "userNo": "123-2", " ...
- 排序算法 java实现2
继续排序算法 4.冒泡排序 从第一个开始,跟后面一个数比较,如果比后面大就交换位置,这样没完成一轮,就可以把最大的选出来 public static <T extends Comparable& ...
- BZOJ5334: [Tjoi2018]数学计算
BZOJ5334: [Tjoi2018]数学计算 https://lydsy.com/JudgeOnline/problem.php?id=5334 分析: 线段树按时间分治即可. 代码: #incl ...
- 如何开启MySQL远程访问权限 允许远程连接
1.改表法. 可能是你的帐号不允许从远程登陆,只能在localhost.这个时候只要在localhost的那台电脑,登入mysql后,更改 "mysql" 数据库里的 " ...
- Qt Creator 中自动补全的快捷键描述
在TextEdit中的completeThis