I've deployed a node.js service (REST API) in GCP Run and I'm having issues with the TLS handshake in Flutter.
Unhandled Exception: HandshakeException: Handshake error in client (OS Error: WRONG_VERSION_NUMBER(tls_record.cc:242))
The code that I'm trying to use is:
static Future<http.Response> get(String url, {Map<String, String>? headers}) async {
final _headers = await _addAuthHeader(headers); //appends the authorization header (not used right now)
final out = await http.get(Uri.parse(url), headers: _headers); //this throws the exception
return out;
}
In GCP Run I've haven't set anything about the security other than the allow unauthenticated calls so I should be using the managed TLS service.
I've tested in the following conditions:
curl https://<url> works ✅
curl --tls-max 1.2 https://<url> works ✅
curl --tls-max 1.1 https://<url> doesn't work ❌ (maybe Flutter doesn't support TLS 1.2?)
In dart (HTTPS call) using dio package doesn't work ❌
In dart (HTTPS call) using http package doesn't work ❌
In dart (HTTP call) works ✅
In chrome works ✅
I've tried the solutions proposed in these other posts:
Why i'm getting WRONG_VERSION_NUMBER when making a POST request to a HTTPS Server?
How to solve Flutter CERTIFICATE_VERIFY_FAILED error while performing a POST request?
Flutter on Android 7 CERTIFICATE_VERIFY_FAILED with LetsEncrypt SSL cert after Sept 30, 2021
System information:
Flutter version: 3.3.8
Dart version: 2.18.4
Flutter doctor: everything fine
Related
I'm using Flutter version 3.3.8 and Google Chrome version 107.0.5304.110.
I send an http request, and this is the error that I get:
ChromeProxyService: Failed to evaluate expression 'xhr': InternalError: Expression evaluation in async frames is not supported. No frame with index 30..
The route to which you send the request may be of type post and you send the request with get or vice versa
i'm trying to connect to websocket server with token in header.
Due to web_socket_channel package not support headers i'm using dart WebSocket class.
I'm struggling with error in console:
"WebSocketException: Connection to 'https://URL:0/messenger#' was not upgraded to websocket<…>"
My code sample:
_url = 'wss://URL/messenger'
channel = await WebSocket.connect(
_url,
protocols: _protocols,
headers: {
"Cookie": "realtalk_auth=$token",
},
);
Also, same url in Postman with header "Cookie: realtalk_auth=token" lead to success connection
I want to post data to the server with dio library but when I send data, I get XMLHttpRequest error. The server programmer checked twice his codes and made sure to enable CORS in the server. I think this error occurs because the server is not HTTPS and the browser blocks the request. I use this code to send my data to the server:
Response response = await client
.post(theUrl,
options: Options(
validateStatus: (status) {
return status! < 500;
},
followRedirects: false,
headers: {
HttpHeaders.contentTypeHeader: "application/json",
HttpHeaders.acceptHeader: "*/*",
HttpHeaders.accessControlAllowOriginHeader:
"Access-Control-Allow-Origin, Accept",
}),
data: convert.json.encode(data))
.timeout(const Duration(seconds: 10));
My log is just:
DioError [DioErrorType.RESPONSE]: XMLHttpRequest error.
So, How can I ignore the certificate of the server host and send data to an HTTP URL in flutter web?
I'm almost sure that the problem is because your server doesn't have an https certificate.
A workaround is run / debug your application with flutter desktop.
You can also take a look at: How to solve flutter web api cors error only with dart code?
I created an app and test it on emulator and andriod phone, i am using api's and nodejs based backend and mongodb database. it works fine when i test it on devices, but when i run it on chrome it sends me this error.
Error:
Error: Unsupported operation: NetworkInterface.list
DioError [DioErrorType.response]: XMLHttpRequest error.
here is my dio request code
Code:
calltimeInApi() async {
Dio dio=new Dio();
var data={
'username': getname,
'token': getaccesstoken,
};
timeOutButtonPressed=true;
await dio
.post(localhostUrlTimeIn,data: json.encode(data))
.then((onResponse)async {
getapitimein=onResponse.data['TimeIn'];
}).catchError((onerror){
print(onerror.toString());
});
}
please help where i am doing wrong!
There doesn't seem to be any issues on the code snippet that you've shared. If the HTTP Requests works fine on mobile devices but not on web, I suggest check the logs if you're getting CORS errors. A quick workaround on this issue is by running the web app with html renderer in debug.
flutter run -d chrome --web-renderer html
I am building a flutter app which needs to connect to the server and exchange data using websocket. The server is in JAVA and using SockJs and Stomp to implement this functionality.
I am using Stomp dart client and webSocket packages from pub.dev/packages.
This is the part of my code where I am trying to connect :
clientConnect() async {
String cookie = await storage.read(key: "cookie");
final stompClient = StompClient(
config: StompConfig(url: 'ws://192.168.0.13:8080/....', onConnect: onConnect,
webSocketConnectHeaders: {"cookie": cookie }));
stompClient.activate();
}
The problem I am facing is, my flutter app is not able to connect to the server and throws the this error.
WebSocketException: Connection to 'http://192.168.0.12:8080/....' was not upgraded to websocket
Late answer (maintainer of the stomp package):
Since you seem to be using StompJS on the java-side you need to use the special StompJS config in the client. Here is the example from the documentation:
https://pub.dev/packages/stomp_dart_client#use-stomp-with-sockjs
StompClient client = StompClient(
config: StompConfig.SockJS(
url: 'https://yourserver',
onConnect: onConnectCallback
)
);