“DART, wie man JSON in X-Www-Form-Urlencoded umwandelt” Code-Antworten

DART, wie man JSON in X-Www-Form-Urlencoded umwandelt

  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, wie man JSON in X-Www-Form-Urlencoded umwandelt

  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

Ähnliche Antworten wie “DART, wie man JSON in X-Www-Form-Urlencoded umwandelt”

Fragen ähnlich wie “DART, wie man JSON in X-Www-Form-Urlencoded umwandelt”

Weitere verwandte Antworten zu “DART, wie man JSON in X-Www-Form-Urlencoded umwandelt” auf JavaScript

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen