Created
March 2, 2020 16:22
-
-
Save nichotined/96261aa5d6795e9eae2c90c63514cf68 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun toCurlRequest(request: Request): String? { | |
val builder = StringBuilder("curl -v ") | |
// Method | |
builder.append("-X ").append(request.method).append(" \\\n ") | |
// Headers | |
for ((key, value1) in request.headers) { | |
builder.append("-H \"").append(key).append(":") | |
for (value in value1) builder.append("").append(value) | |
builder.append("\" \\\n ") | |
} | |
// Body | |
builder.append("-d '").append(String(request.body)).append("' \\\n ") | |
// URL | |
builder.append("\"").append(request.url).append("\"") | |
return builder.toString() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment