安装 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网络通讯的更多相关文章

  1. dicom网络通讯入门(3)

    接下来可以进行消息传递了 ,也就是dimse ,再来复习下 什么是dimse .n-set  n-create c-echo 这些都是dimse  他们都是属于一种结构的pdu 那就是tf-pdu(传 ...

  2. dicom网络通讯入门(2)

    第二篇,前面都是闲扯 其实正文现在才开始,这次是把压箱底的东西都拿出来了. 首先我们今天要干的事是实现一个echo响应测试工具 也就是echo 的scu,不是实现打印作业管理么.同学我告诉你还早着呢. ...

  3. 《连载 | 物联网框架ServerSuperIO教程》-4.如开发一套设备驱动,同时支持串口和网络通讯。附:将来支持Windows 10 IOT

    1.C#跨平台物联网通讯框架ServerSuperIO(SSIO)介绍 <连载 | 物联网框架ServerSuperIO教程>1.4种通讯模式机制. <连载 | 物联网框架Serve ...

  4. Windows 网络通讯开发

    Windows 网络通讯开发 一.Windows网络开发API 由于C++标准库中没有网络库,所以进行网络开发的时候要调用系统API.Windows通讯开发API包括以下几个基本函数及成员类型: 1. ...

  5. 文档:网络通讯包结构(crc校验,加解密)

    一直想把这个流程整理一下. 包结构: 包 对(datacrc+protoID+dataSize)组成的byte[] 进行crc计算而得到 对(数据内容)进行crc计算而得到 协议号 数据内容的字节长度 ...

  6. 网络--三种网络通讯方式及Android的网络通讯机制

    Android平台有三种网络接口可以使用,他们分别是:java.net.*(标准Java接口).Org.apache接口和Android.net.*(Android网络接口).下面分别介绍这些接口的功 ...

  7. DIOCP网络通讯流程

    DIOCP 运作核心探密   原文连接: http://blog.qdac.cc/?p=2362 原作者: BB 天地弦的DIOCP早已经广为人知了,有很多的同学都用上了它,甚至各种变异.修改版本也出 ...

  8. Socket网络通讯开发总结之:Java 与 C进行Socket通讯 + [备忘] Java和C之间的通讯

    Socket网络通讯开发总结之:Java 与 C进行Socket通讯 http://blog.sina.com.cn/s/blog_55934df80100i55l.html (2010-04-08 ...

  9. 如何在Windows系统上用抓包软件Wireshark截获iPhone等网络通讯数据

    http://www.jb51.net/os/windows/189090.html 今天给大家介绍一种如何在Windows操作系统上使用著名的抓包工具软件Wireshark来截获iPhone.iPa ...

随机推荐

  1. js比较函数

    //1.//bySort函数接受一个首要比较字符串和一个可选的次要比较函数做为参数//并返回一个可以用来包含该成员的对象数组进行排序的比较函数//当o[firstName] 和 p[firstName ...

  2. 按返回键退出程序但不销毁代码,像QQ一样,后台运行

    @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BA ...

  3. 剑指offer--21.链表中倒数第k个结点

    定义两个指针,当一个指针指到第K个结点时,第二个指针开始向后移动 -------------- 时间限制:1秒 空间限制:32768K 热度指数:602826 本题知识点: 链表 题目描述 输入一个链 ...

  4. BEC listen and translation exercise 11

    When you are in any contest you should work as if there were — to the very last minute — a chance to ...

  5. New Year and Counting Cards

    Your friend has n cards. You know that each card has a lowercase English letter on one side and a di ...

  6. Python 2.7_利用xpath语法爬取豆瓣图书top250信息_20170129

    大年初二,忙完家里一些事,顺带有人交流爬取豆瓣图书top250 1.构造urls列表 urls=['https://book.douban.com/top250?start={}'.format(st ...

  7. 【LeetCode】004. Median of Two Sorted Arrays

    题目: There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the ...

  8. mapreduce-实现多表关联

    //map package hadoop3; import java.io.IOException; import org.apache.hadoop.io.LongWritable;import o ...

  9. 常用Request对象获取请求信息

    Request.ServerVariables(“REMOTE_ADDR”) ‘获取访问IPRequest.ServerVariables(“LOCAL_ADDR”) ‘同上Request.Serve ...

  10. Raid信息丢失数据恢复及oracle数据库恢复验证方案

    早些时候,有个客户14块盘的磁盘阵列出现故障,需要恢复的数据是oracle数据库,客户在寻求数据恢复技术支持,要求我提供详细的数据恢复方案,以下是提供给客户的详细数据恢复解决方案,本方案包含Raid数 ...