Skip to content

Commit

Permalink
simple support x-www-form-urlencoded for client
Browse files Browse the repository at this point in the history
  • Loading branch information
pwrshi committed May 5, 2024
1 parent 8c239f9 commit 3c09a20
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion lib/src/generators/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,24 @@ class $clientName {
request = request as http.Request;
try {
if (body != null) {
request.body = json.encode(body);
switch (requestType) {
case 'application/x-www-form-urlencoded':
var parts = [];
Map<String, String> bodyMap =
Map<String, String>.from(body as Map<dynamic, dynamic>);
bodyMap.forEach((key, value) {
String encodedPart =
'\${Uri.encodeQueryComponent(key)}=\${Uri.encodeQueryComponent(value)}';
parts.add(encodedPart);
});
request.body = parts.join('&');
break;
default:
request.body = json.encode(body);
break;
}
}
} catch (e) {
// Handle request encoding error
Expand Down

0 comments on commit 3c09a20

Please sign in to comment.