php curl,如何使用php中的curl方法向服务器发送post请求?

用户投稿 112 0

关于“php_curl_网页内容”的问题,小编就整理了【1】个相关介绍“php_curl_网页内容”的解答:

如何使用php中的curl方法向服务器发送post请求?

用PHP向服务器发送HTTP的POST请求,代码如下:

<?php/** * 发送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; }

到此,以上就是小编对于“php_curl_网页内容”的问题就介绍到这了,希望介绍关于“php_curl_网页内容”的【1】点解答对大家有用。

抱歉,评论功能暂时关闭!