Android上的React-native POST请求通过https返回网络错误 [英] React-native POST request in android over https return network error

查看:410
本文介绍了Android上的React-native POST请求通过https返回网络错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图在带有axios的react-native下通过https POST请求创建用户帐户,而在android上总是由于网络错误"而失败.

Tried to create user account through https POST request under react-native with axios, while it always failed on android with a 'network error'.

axios('https://'+DEST_URI, {
 method: 'post',
 data: account,
 headers: {
   'Accept': 'application/json',
 }
 then(...)

相同的https POST请求在iOS上可以正常运行.

The same https POST request works fine on iOS.

更改为http,相同的POST请求也适用于android.

Changed to http, the same POST request works on android as well.

还尝试通过android上的https进行GET请求,它可以按预期从后端服务器检索数据.

Also tried GET request through https on android, it could retrieve data from the backend server as expected.

有什么想法吗?

链接的图像是控制台日志的输出, 控制台日志中的输出

Linked image is the output from console log, output from console log

推荐答案

与问题有关在本机存储库上升级到OkHttp3 .

从代理中停用http2,这是导致问题的原因. 您可以尝试升级到他们在变更日志中提到的react-native v0.27,他们解决了此问题,但对我而言却行不通.

Deactivate http2 from your proxy that is what causing the problem. You can try to upgrade to react-native v0.27 they mention in the change log that they fixed this problem but for me didn't work.

我必须禁用ngnix中的http2功能才能使其正常工作.

I had to disable the http2 feature in ngnix to make it work.

禁用http2确实很简单,只需从以下位置更改ngnix配置文件中的这一行:

disabling http2 really is this simple, just change this line in your ngnix config file from:

listen 443 ssl http2;

listen 443 ssl;

然后重新加载您的配置:

then reload your config:

service nginx reload

有关http2和ngnix的更多信息,请参见此处

More info about http2 and ngnix can be found here

这篇关于Android上的React-native POST请求通过https返回网络错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆