Update webpagetool.php

This commit is contained in:
Namhyeon Go 2019-02-20 20:51:35 +09:00 committed by GitHub
parent 9e3442f623
commit e25ea2331a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -54,7 +54,7 @@ if(!function_exists("get_web_cmd")) {
} }
if($method == "get") { if($method == "get") {
$args[] = sprintf("-A '%s'", make_safe_argument($ua)); // set agent $args[] = sprintf("-A '%s'", get_web_user_agent($ua)); // set agent
$args[] = "-k"; // allow self-signed certificate (the same as --insecure) $args[] = "-k"; // allow self-signed certificate (the same as --insecure)
foreach($headers as $k=>$v) { foreach($headers as $k=>$v) {
// the same as --header // the same as --header
@ -65,7 +65,7 @@ if(!function_exists("get_web_cmd")) {
if($method == "post") { if($method == "post") {
$args[] = "-X POST"; // set post request (the same as --request) $args[] = "-X POST"; // set post request (the same as --request)
$args[] = sprintf("-A '%s'", make_safe_argument($ua)); // set agent $args[] = sprintf("-A '%s'", get_web_user_agent($ua)); // set agent
$args[] = "-k"; // allow self-signed certificate (the same as --insecure) $args[] = "-k"; // allow self-signed certificate (the same as --insecure)
foreach($headers as $k=>$v) { foreach($headers as $k=>$v) {
// the same as --header // the same as --header
@ -85,7 +85,7 @@ if(!function_exists("get_web_cmd")) {
if($method == "jsondata") { if($method == "jsondata") {
$data_string = json_encode($data); $data_string = json_encode($data);
$args[] = "-X POST"; // set post request (the same as -X) $args[] = "-X POST"; // set post request (the same as -X)
$args[] = sprintf("-A '%s'", make_safe_argument($ua)); // set agent $args[] = sprintf("-A '%s'", get_web_user_agent($ua)); // set agent
$args[] = "-k"; // allow self-signed certificate (the same as --insecure) $args[] = "-k"; // allow self-signed certificate (the same as --insecure)
$headers['Content-Type'] = "application/json"; $headers['Content-Type'] = "application/json";
$headers['Content-Length'] = strlen($data_string); $headers['Content-Length'] = strlen($data_string);
@ -243,7 +243,7 @@ if(!function_exists("get_web_curl")) {
); );
if(empty($options[CURLOPT_USERAGENT])) { if(empty($options[CURLOPT_USERAGENT])) {
$ua = "ReasonableFramework/1.1 (https://github.com/gnh1201/reasonableframework)"; $ua = get_web_user_agent($ua);
$options[CURLOPT_USERAGENT] = $ua; $options[CURLOPT_USERAGENT] = $ua;
} }
@ -308,11 +308,9 @@ if(!function_exists("get_web_page")) {
$errno = false; $errno = false;
$content = false; $content = false;
$req_method = $method; $req_method = $method;
// set user agent // set user agent
if(empty($ua)) { $ua = get_web_user_agent($ua);
$ua = "ReasonableFramework/1.1 (https://github.com/gnh1201/reasonableframework)";
}
// redefine data // redefine data
$headers = array(); $headers = array();
@ -546,3 +544,14 @@ if(!function_exists("get_webproxy_url")) {
)); ));
} }
} }
if(!function_exists("get_web_user_agent")) {
function get_web_user_agent($ua="") {
if(empty($ua)) {
$ua = "ReasonableFramework/1.1 (https://github.com/gnh1201/reasonableframework)";
} else {
$ua = make_safe_argument($ua);
}
return $ua;
}
}