php生成curl命令行的方法
《:php生成curl命令行的方法》要点: PHP应用本篇章节讲解php生成curl命令行的办法.分享给大家供大家参考,具体如下: 示例: 具体代码如下: function getCurlCommand() { try { if (php_sapi_name() == 'error cli'){ throw new Exception("cli"); } $curlCommand = 'curl '; $postData = $getData = ''; if($_GET) { $gets = http_build_query($_GET); $getData .= strpos($curlCommand,'?') ? '&' . $gets : '?' . $gets; } if ($_SERVER['REQUEST_METHOD'] == 'POST' ) { $posts = http_build_query($_POST); $postData = ' -d "' . $posts . '"'; } $path = isset($_SERVER['SCRIPT_NAME']) ? $_SERVER['SCRIPT_NAME'] : $_SERVER['PHP_SELF']; $curlCommand .= '"' . "http://{$_SERVER['HTTP_HOST']}" . $path . $getData . '"'; if ($postData) { $curlCommand .= $postData; } $headers = array(); if (function_exists('getallheaders')) { $headers = getallheaders(); } else { foreach ($_SERVER as $name => $value) { if (substr($name,5) == 'HTTP_') { $headers[str_replace(' ','-',ucwords(strtolower(str_replace('_',' ',substr($name,5)))))] = $value; } } } foreach ($headers as $key => $value) { if($key == 'Accept-Encoding') $value = str_replace('gzip,','',$value); $curlCommand .= ' -H "' . $key . ':' . $value . '"'; } return $curlCommand; } catch (Exception $e) { return $e->getMessage(); } } echo getCurlCommand(); 希望本文所述对大家php程序设计有所赞助. 《:php生成curl命令行的方法》是否对您有启发,欢迎查看更多与《:php生成curl命令行的方法》相关教程,学精学透。编程之家 52php.cn为您提供精彩教程。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |