Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to keep http connection alive for React Native's fetch method

I am trying to use RN's fetch() method with http connection alive.
I tried with header 'Connection: keep-alive' but it does not seem to work. I cannot use http.Agent because http module is not supported in React Native. I searched but cannot find an alternative module.(XmlHttpRequest does not work also)

Question: What can I do to keep http connection alive in React Native's environment?

My ultimate purpose is to authenticate a NTLM server in React Native's JavaScriptCore, the authentication needs keep-alive http connection. Any other suggestion is also appreciated.

like image 306
Wint Avatar asked May 30 '26 18:05

Wint


1 Answers

On Android (and presumably similarly on iOS), the OkHttp client used by ReactNative will by default keep either a Http/1.1 or Http/2 connection alive and reuse it. You should check whether the server is closing the response.

https://en.wikipedia.org/wiki/HTTP_persistent_connection#HTTP_1.1

like image 151
Yuri Schimke Avatar answered Jun 02 '26 09:06

Yuri Schimke



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!