0

I am going to run localhost .net API in a flutter to get data from it but I got a lot of errors. why.net API is locally hosted. I want to run a local web API I don't want to host it on a live server.

here is code

static Future fectchCordinates() async
{
    HttpClient client = new HttpClient();
    client.badCertificateCallback = ((X509Certificate cert, String host, int port) => true);
    var studentUrl =Uri.parse('https://10.0.2.2:44363/address-lookup?address=house%20no%20122%20');
    //Uri.parse(studentUrl),
    print(studentUrl);
    http.Response response=await http.get(studentUrl,headers: {"Accept": "application/json"});
    print(response.body);
    return response;
} 

E/flutter ( 8373): [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: HandshakeException: Handshake error in client (OS Error:
E/flutter ( 8373): CERTIFICATE_VERIFY_FAILED: unable to get local issuer certificate(handshake.cc:393))
E/flutter ( 8373): #0 _SecureFilterImpl._handshake (dart:io-patch/secure_socket_patch.dart:99:46)
E/flutter ( 8373): #1 _SecureFilterImpl.handshake (dart:io-patch/secure_socket_patch.dart:142:25)
E/flutter ( 8373): #2 _RawSecureSocket._secureHandshake (dart:io/secure_socket.dart:911:54)
E/flutter ( 8373): #3 _RawSecureSocket._tryFilter (dart:io/secure_socket.dart:1040:19)
E/flutter ( 8373):
E/flutter ( 8373):

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
  • TLS is failing which occurs before the HTTP Request is sent. The encryption mode, TLS mode, or certificate is not compatible between client and server. You are using Localhost. What port number are you using? The port may be blocked or being used by another application. May be the IP address is wrong. – jdweng Jul 05 '22 at 15:54
  • You create a client with a bad callback function, but never use it! – Richard Heap Jul 05 '22 at 22:21

1 Answers1

0

try to call your local api with http and replace house%20... with correct end point: http://10.0.2.2:44363/address-lookup?address=house"YourCorrectEndPoint"

or try to use this link

Hossein Asadi
  • 768
  • 1
  • 6
  • 15