“DART Cómo convertir JSON a X-www-form-urlencoded” Código de respuesta

DART Cómo convertir JSON a X-www-form-urlencoded

  Future<HttpClientResponse> foo() async {
    Map<String, dynamic> jsonMap = {
      'homeTeam': {'team': 'Team A'},
      'awayTeam': {'team': 'Team B'},
    };
    String jsonString = json.encode(jsonMap); // encode map to json
    String paramName = 'param'; // give the post param a name
    String formBody = paramName + '=' + Uri.encodeQueryComponent(jsonString);
    List<int> bodyBytes = utf8.encode(formBody); // utf8 encode
    HttpClientRequest request =
        await _httpClient.post(_host, _port, '/a/b/c');
    // it's polite to send the body length to the server
    request.headers.set('Content-Length', bodyBytes.length.toString());
    // todo add other headers here
    request.add(bodyBytes);
    return await request.close();
  }
Grumpy Gorilla

DART Cómo convertir JSON a X-www-form-urlencoded

  Map<String, String> body = {
    'name': 'doodle',
    'color': 'blue',
    'homeTeam': json.encode(
      {'team': 'Team A'},
    ),
    'awayTeam': json.encode(
      {'team': 'Team B'},
    ),
  };

  Response r = await post(
    url,
    body: body,
  );
Grumpy Gorilla

Respuestas similares a “DART Cómo convertir JSON a X-www-form-urlencoded”

Preguntas similares a “DART Cómo convertir JSON a X-www-form-urlencoded”

Más respuestas relacionadas con “DART Cómo convertir JSON a X-www-form-urlencoded” en JavaScript

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código