
正文
php怎么写请求数据 php 请求接口方式有几种
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
php curl多线程发送数据请求怎么写
//curl
protected function https_CURL($url, $data = null) {
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
if (!empty($data)) {
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
}
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($curl);
curl_close($curl);
return $output;
}
相关问答
Q1: php语言,用服务器发送一个post请求怎么写?比如往百度首页发送post数据(a=1&b=2)
function POST($Url,$Argv){
$flag = 0;
$post = '';
$errno = '';
$errstr = '';
foreach($Argv as $key = $value){
if($flag != 0){
$post .= "";
$flag = 1;
}
$post .= $key . "=";
$post .= urlencode($value);
$flag = 1;
}
$length = strlen($post);
$fp = fsockopen("localhost",80,$errno,$errstr,10) or exit($errstr."---".$errno);
$header = "POST " . $Url . " HTTP/1.1\r\n";
$header .= "Host:127.0.0.1\r\n";
$header .= "Referer:/flandy/post.php\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . $length . "\r\n";
$header .= "Connection: Close\r\n\r\n";
$header .= $post . "\r\n";
fputs($fp,$header);
$inheader = 1;
$Return = '';
while(!feof($fp)){
$line = fgets($fp,1024);
if($inheader ($line == "\n" || $line == "\r\n"))$inheader = 0;
if($inheader == 0) $Return .= $line;
}
fclose($fp);
return trim($Return);
}
//调用方式
$Result = POST('xxxxxURLxxx',array('dataName' = 'dataValue'));
Q2: 如何用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);
Q3: php请求第三方数据方法
方法有很多,其中有file_get_contents把数据读到一个字符串中,还有一个是curl方式,两种方式有所不同,查一下就知道区别了
关于php怎么写请求数据和php 请求接口方式有几种的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。







