您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

php生成curl命令行的方法

2024/5/22 3:57:22发布43次查看
本文实例讲述了php生成curl命令行的方法。分享给大家供大家参考,具体如下:
示例:
curl http://localhost/other/serverinfo.php?dd=ddd -h host:localhost -h connection:keep-alive -h cache-control:max-age=0 -h accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8 -h user-agent:mozilla/5.0 (windows nt 6.1; wow64) applewebkit/537.36 (khtml, like gecko) chrome/43.0.2357.132 safari/537.36 -h dnt:1 -h accept-encoding:deflate, sdch -h accept-language:zh-cn,zh;q=0.8,en;q=0.6 -h cookie:name=richie; email=richie@qq.com
具体代码如下:
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, 0, 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命令行的方法,包括了exception方面的内容,希望对php教程有兴趣的朋友有所帮助。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product