post method

Future post(
  1. String endPoint,
  2. Map data
)

Make a custom post request to Woocommerce, using WooCommerce SDK.

Implementation

Future<dynamic> post(
  String endPoint,
  Map data,
) async {
  String url = this._getOAuthURL("POST", endPoint);

  http.Client client = http.Client();
  http.Request request = http.Request('POST', Uri.parse(url));
  request.headers[HttpHeaders.contentTypeHeader] =
      'application/json; charset=utf-8';
  //request.headers[HttpHeaders.authorizationHeader] = _bearerToken;
  request.headers[HttpHeaders.cacheControlHeader] = "no-cache";
  request.body = json.encode(data);
  String response =
      await client.send(request).then((res) => res.stream.bytesToString());
  var dataResponse = await json.decode(response);
  _handleError(dataResponse);
  return dataResponse;
}