
正文
php请求服务器上数据,php请求接口数据
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
如何用php向服务器发送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;
}
使用的时候直接调用上面定义的send_post方法:
$post_data = array(
'username' = 'username',
'password' = 'password'
);
send_post('网址', $post_data);
相关问答
Q1: php怎么以post方式发送数据
:用PHP向服务器发送HTTP的POST请求,代码如下:?php/***发送post请求*@paramstring$url请求地址*@paramarray$post_datapost键值对数据*@returnstring*/.
Q2: php如何将表单数据提交给远程服务器
朋友,我来告诉你答案!方式一:用GET方式直接把数据写在地址栏里
方式二:action里写上远程服务器地址,把表单数据写在hidden里POST给对方
Q3: 如何用php实现接收发送到服务器的数据。。。。。。。
1、直接file_get_contents("php://input") 这个函数就可以接到接口传参!
2、建议使用json格式数据进行交互。
Q4: php socket往服务器端发送数据
据我的了解,socket就是单独的线程,一直启用,php请求才会响应,否则待命。
你的socket需要考虑的是并发的问题,别的没有什么。
php-socket-服务器-socket-php







