Last active
December 16, 2015 15:50
-
-
Save ma2thieu/5459209 to your computer and use it in GitHub Desktop.
testing jembe.http.get() in the browser
This file contains hidden or 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
<?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); |
This file contains hidden or 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
// (...) | |
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