I am working on flutter application with AWS AppSync in that I am using the end URL of AWS server but when I try to execute the query I am getting below error
I am working in proxy setting but is not effecting this URL it's working perfectly in native android application
SocketException: OS Error: Connection refused, errno = 111, address = XXXXXXXXXXXXX.appsync-api.ap-south-1.amazonaws.com port -43872
I have a search on google but they mention the internet permission in not added in the manifest file but after added the permission I am facing the same issue.
Below is the code on the AWS app sync execute method where I am getting the error.
Future<Map> execute({
@required String endpoint,
@required String query,
@required Map variables,
@required String accessToken,
Database cache,
CachePriority priority = CachePriority.network,
}) async {
var body = jsonEncode({"query": query, "variables": variables});
Future<Map> loadFromCache() async {
var cacheKey = getCacheKey(endpoint, body);
var data = await readCache(cache, cacheKey);
if (data != null) {
logger.fine(
'loaded from cache (endpoint: ${endpoint.toRepr()}, requestBody: ${body.toRepr()}, cacheKey: $cacheKey)',
);
}
return data;
}
if (cache != null && priority == CachePriority.cache) {
var data = await loadFromCache();
if (data != null) return data;
}
logger.fine('POST ${endpoint.toRepr()} - ${body.toRepr()}');
http.Response response;
try {
response = await http.post(
endpoint,
headers: {
HttpHeaders.authorizationHeader: AWSaccessToken,
HttpHeaders.contentTypeHeader: ContentType.json.mimeType,
"x-api-key" :AWS_APP_SYNC_KEY,
},
body: body,
);
} catch (e) {
var shouldFallback = cache != null && priority == CachePriority.network;
if (!shouldFallback || !isNetworkError(e)) rethrow;
logger.finest('network error encountered; falling back to cache - $e');
var data = await loadFromCache();
if (data != null) {
return data;
} else {
rethrow;
}
}
if (response.statusCode != HttpStatus.ok) {
throw HttpError(response);
}
logger.fine(
'loaded from network (endpoint: ${endpoint.toRepr()}, requestBody: ${body.toRepr()})',
);
var result = jsonDecode(response.body);
var data = result["data"];
if (cache != null) {
var cacheKey = getCacheKey(endpoint, body);
await updateCache(cache, cacheKey, data);
logger.fine(
'updated cache (endpoint: ${endpoint.toRepr()}, requestBody: ${body.toRepr()}, cacheKey: $cacheKey)',
);
}
return data;
}