扑朔迷离的AWS AppSync中的Ssocket异常

时间:2020-07-25 06:23:58

标签: android flutter aws-amplify flutter-dependencies aws-appsync

我正在使用AWS AppSync处理Flutter应用程序,因为我正在使用AWS服务器的结束URL,但是当我尝试执行查询时,却遇到了错误

我正在使用代理服务器设置,但没有影响此URL,它在本机android应用程序中运行正常

SocketException:操作系统错误:连接被拒绝,errno = 111,地址= XXXXXXXXXXXXX.appsync-api.ap-south-1.amazonaws.com端口-43872

我在Google上进行了搜索,但他们提到的Internet权限未添加到清单文件中,但是添加了权限后,我也遇到了同样的问题。

下面是我收到错误的AWS应用程序同步执行方法上的代码。

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;
}

1 个答案:

答案 0 :(得分:0)

您连接到错误的端口,这意味着您从客户端连接到的端口没有侦听器/服务器,或者该端口和公共IP在服务器端未暴露给Internet

相关问题