doPostRequest method

Future<Response> doPostRequest(
  1. Uri uri,
  2. Map<String, String> body,
  3. User? user, {
  4. QueryType? queryType,
  5. required bool addCredentialsToBody,
  6. bool addCredentialsToHeader = false,
})

Send a http post request to the specified uri. The data / body of the request has to be provided as map. (key, value) The result of the request will be returned as string.

addCredentialsToBody should be only use for Robotoff, See: https://github.com/openfoodfacts/openfoodfacts-dart/issues/553#issuecomment-1269810032 When using addCredentialsToBody a User or globalUser needed, blocks QueryType.TEST authentication

Implementation

Future<http.Response> doPostRequest(
  Uri uri,
  Map<String, String> body,
  User? user, {
  QueryType? queryType,
  required bool addCredentialsToBody,
  bool addCredentialsToHeader = false,
}) async {
  if (addCredentialsToBody) {
    if (user != null) {
      body.addAll(user.toData());
    }
  }

  http.Response response = await http.post(
    uri,
    headers: _buildHeaders(
      user: user,
      isTestModeActive:
          OpenFoodAPIConfiguration.getQueryType(queryType) != QueryType.PROD,
      addCredentialsToHeader: addCredentialsToHeader,
    ),
    body: addUserAgentParameters(body),
  );
  return response;
}