mirror of
https://github.com/foss42/apidash.git
synced 2025-08-06 13:51:20 +08:00
Update curl.dart
This commit is contained in:
@ -167,51 +167,54 @@ class Curl extends Equatable {
|
|||||||
var cmd = 'curl ';
|
var cmd = 'curl ';
|
||||||
|
|
||||||
// Add the request method
|
// Add the request method
|
||||||
if (method != 'GET') {
|
if (method != 'GET' && method != 'HEAD') {
|
||||||
cmd += '-X $method ';
|
cmd += '-X $method ';
|
||||||
}
|
}
|
||||||
|
if (method == 'HEAD') {
|
||||||
|
cmd += '-I ';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add the URL
|
||||||
|
cmd += '"${Uri.encodeFull(uri.toString())}" ';
|
||||||
|
|
||||||
// Add the headers
|
// Add the headers
|
||||||
headers?.forEach((key, value) {
|
headers?.forEach((key, value) {
|
||||||
cmd += '-H "$key: $value" ';
|
cmd += '\\\n -H "$key: $value" ';
|
||||||
});
|
});
|
||||||
|
|
||||||
// Add the body
|
// Add the body
|
||||||
if (data?.isNotEmpty == true) {
|
if (data?.isNotEmpty == true) {
|
||||||
cmd += '-d \'$data\' ';
|
cmd += "\\\n -d '$data' ";
|
||||||
}
|
}
|
||||||
// Add the cookie
|
// Add the cookie
|
||||||
if (cookie?.isNotEmpty == true) {
|
if (cookie?.isNotEmpty == true) {
|
||||||
cmd += '-b \'$cookie\' ';
|
cmd += "\\\n -b '$cookie' ";
|
||||||
}
|
}
|
||||||
// Add the user
|
// Add the user
|
||||||
if (user?.isNotEmpty == true) {
|
if (user?.isNotEmpty == true) {
|
||||||
cmd += '-u \'$user\' ';
|
cmd += "\\\n -u '$user' ";
|
||||||
}
|
}
|
||||||
// Add the referer
|
// Add the referer
|
||||||
if (referer?.isNotEmpty == true) {
|
if (referer?.isNotEmpty == true) {
|
||||||
cmd += '-e \'$referer\' ';
|
cmd += "\\\n -e '$referer' ";
|
||||||
}
|
}
|
||||||
// Add the user-agent
|
// Add the user-agent
|
||||||
if (userAgent?.isNotEmpty == true) {
|
if (userAgent?.isNotEmpty == true) {
|
||||||
cmd += '-A \'$userAgent\' ';
|
cmd += "\\\n -A '$userAgent' ";
|
||||||
}
|
}
|
||||||
// Add the form flag
|
// Add the form flag
|
||||||
if (form) {
|
if (form) {
|
||||||
cmd += '-F ';
|
cmd += " \\\n -F ";
|
||||||
}
|
}
|
||||||
// Add the insecure flag
|
// Add the insecure flag
|
||||||
if (insecure) {
|
if (insecure) {
|
||||||
cmd += '-k ';
|
cmd += " \\\n -k ";
|
||||||
}
|
}
|
||||||
// Add the location flag
|
// Add the location flag
|
||||||
if (location) {
|
if (location) {
|
||||||
cmd += '-L ';
|
cmd += " \\\n -L ";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the URL
|
|
||||||
cmd += '"${Uri.encodeFull(uri.toString())}"';
|
|
||||||
|
|
||||||
return cmd.trim();
|
return cmd.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user