5虎吧:php源码下载-免费主题模板-热门资源-自助广告插件-自助广告源码
PHP发送POST请求
当前位置:首页 > 技术教程

PHP发送POST请求

5虎吧 技术教程 599

5虎吧本次为大家分享的是PHP发送POST请求


/**

* 发送post请求

* @param string $url 请求地址

* @param array $post_data post键值对数据

* @return string

*/

function send_post($url, $post_data) {

$postdata = http_build_query($post_data);

$options = array(

'http' => array(

'method' => 'POST',

'header' => 'Content-type:application/x-www-form-urlencoded',

'content' => $postdata,

'timeout' => 15 * 60 // 超时时间(单位:s)

)

);

$context = stream_context_create($options);

$result = file_get_contents($url, false, $context);

return $result;

}

//使用方法

$post_data = array(

'username' => 'stclair2201',

'password' => 'handan'

);

send_post('http://www.jb51.net', $post_data);

    协助本站SEO优化一下,谢谢!
    关键词不能为空

免责声明

本站提供的一切软件、教程和内容信息仅为个人学习测试使用,请在下载后的24个小时之内,从您的电脑或手机中彻底删除上述内容,不得用于任何商业用途,否则后果自负,请支持购买正版软件!如侵犯到您的权益,请及时与我们联系处理。敬请谅解!