Skip to content

Instantly share code, notes, and snippets.

@dmgig
Created March 30, 2016 18:59
Show Gist options
  • Save dmgig/2c57a410a7c6e1bb17b206163a135b5a to your computer and use it in GitHub Desktop.
Save dmgig/2c57a410a7c6e1bb17b206163a135b5a to your computer and use it in GitHub Desktop.
Reverse a cURL call to a URL with GET params
url: <b id="output"></b>
<script type="text/javascript">
var curlToGet = function(curl){
var url, data;
var getParams = function(e, i, arr){
flag = this;
if(i != 0)
if(flag != null && arr[i-1] == "-"+flag)
return e;
}
var getUrl = function(curl){
return curl.split(" ").splice(-1);
}
data = curl.split(" ").map(getParams, "d").filter(function(item){ return !(typeof item === 'undefined'); }).join("&");
url = getUrl(curl);
return url+"?"+data;
}
var curl = "curl -GL -d who_requested=Jon+Smith -d foreign_key=1145592 -d parent_key=68263 -d db=tests -d pn=X-PART -d qty=0 -d action=sell -d serial=FSDFSRTFFDP http://example.com/inventory/request.php";
document.getElementById("output").innerHTML = curlToGet(curl);
// returns http://example.com/inventory/request.php?who_requested=Jon+Smith&foreign_key=1145592&parent_key=68263&db=tests&pn=X-PART&qty=0&action=sell&serial=FSDFSRTFFDP
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment