1. 程式人生 > >php-get和post請求

php-get和post請求

output class ray 工作日 打印 init print bsp clas

1.get請求

<?php

//判斷20130101是否是工作日
//工作日對應結果為 0, 休息日對應結果為 1, 節假日對應的結果為 2;
$url=‘http://www.easybots.cn/api/holiday.php?d=20130101‘;

$output= file_get_contents($url);

?>

2.post請求

<?php
$url = "http://xxxxx";
$post_data = array ("key1" => "value","key2"="value");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url
); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // post數據 curl_setopt($ch, CURLOPT_POST, 1); // post的變量 curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); $output = curl_exec($ch); curl_close($ch); //打印獲得的數據 #print_r($output); ?>

php-get和post請求