requestPOST method

Future<HttpResponse> requestPOST(
  1. HttpClient client,
  2. String url, {
  3. Map<String, String>? headers,
  4. Authorization? authorization,
  5. Map<String, String?>? queryParameters,
  6. bool noQueryString = false,
  7. Object? body,
  8. String? contentType,
  9. String? accept,
  10. String? responseType,
  11. ProgressListener? progressListener,
})

Implementation

Future<HttpResponse> requestPOST(HttpClient client, String url,
    {Map<String, String>? headers,
    Authorization? authorization,
    Map<String, String?>? queryParameters,
    bool noQueryString = false,
    Object? body,
    String? contentType,
    String? accept,
    String? responseType,
    ProgressListener? progressListener}) async {
  var httpBody = HttpRequestBody(body, contentType, queryParameters);
  var requestBody = buildRequestBody(client, httpBody, authorization);

  if (queryParameters != null &&
      queryParameters.isNotEmpty &&
      requestBody.isNull) {
    var requestHeaders = buildRequestHeaders(client, HttpMethod.POST, url,
        headers: headers,
        authorization: authorization,
        contentType: requestBody.contentType,
        accept: accept);

    var formData = buildPOSTFormData(queryParameters, requestHeaders);

    var requestURL = buildRequestURL(client, url,
        authorization: authorization, noQueryString: noQueryString);

    requestURL = await client._interceptRequest(
        HttpMethod.POST, requestURL, requestHeaders);

    return submitHttpRequest(
        client,
        HttpRequest(
          HttpMethod.POST,
          url,
          requestURL,
          authorization: authorization,
          queryParameters: queryParameters,
          withCredentials: _withCredentials(client, authorization),
          requestHeaders: requestHeaders,
          sendData: formData,
          responseType: responseType,
        ),
        progressListener,
        client.logRequests);
  } else {
    var requestHeaders = buildRequestHeaders(client, HttpMethod.POST, url,
        headers: headers,
        authorization: authorization,
        contentType: requestBody.contentType,
        accept: accept);

    var requestURL = buildRequestURL(client, url,
        authorization: authorization,
        queryParameters: queryParameters,
        noQueryString: noQueryString);

    requestURL = await client._interceptRequest(
        HttpMethod.POST, requestURL, requestHeaders);

    return submitHttpRequest(
        client,
        HttpRequest(
          HttpMethod.POST,
          url,
          requestURL,
          authorization: authorization,
          queryParameters: queryParameters,
          withCredentials: _withCredentials(client, authorization),
          requestHeaders: requestHeaders,
          sendData: requestBody.contentAsSendData,
          responseType: responseType,
        ),
        progressListener,
        client.logRequests);
  }
}