Skip to content

Instantly share code, notes, and snippets.

@nichotined
Created March 2, 2020 16:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nichotined/96261aa5d6795e9eae2c90c63514cf68 to your computer and use it in GitHub Desktop.
Save nichotined/96261aa5d6795e9eae2c90c63514cf68 to your computer and use it in GitHub Desktop.
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