Skip to content

Instantly share code, notes, and snippets.

@ma2thieu
Last active December 16, 2015 15:50
Show Gist options
  • Save ma2thieu/5459209 to your computer and use it in GitHub Desktop.
Save ma2thieu/5459209 to your computer and use it in GitHub Desktop.
testing jembe.http.get() in the browser
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $_POST["url"]);
curl_setopt($ch, CURLOPT_HEADER, false);
if ($_POST["headers"] && count($_POST["headers"]) > 0) {
$headers = array();
foreach ($_POST["headers"] as $k => $v) {
$headers[] = $k . ': ' . $v;
}
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
}
if ($_POST["output"]) {
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
}
$result = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
header("HTTP/1.0 " . $status);
if ($_POST["output"]) {
file_put_contents("./jembedocs/" . $_POST["output"], $result, FILE_APPEND | LOCK_EX);
}
curl_close($ch);
// (...)
jembe.http = {
get : function(p_obj) {
$.ajax({
type: "POST",
url: "direct.php",
data: {
"url": p_obj.url,
"headers": p_obj.headers,
"output": p_obj.output
},
success: eval(p_obj.onSuccess),
error:eval(p_obj.onError)
});
}
};
// (...)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment