url,post,cookie。
有这三种就可以了。
下面使用Postman模拟发送。
其中,body中是post参数,header中是cookie数据。
下面是php模拟代码。
public function test_flash() {
$url = 'https://ing.cnblogs.com/ajax/ing/Publish';
$param = [
'content' => '1024',
'publicFlag' => 1
];
$cookie = 'xxx';
$result = json_decode(Http::doPostCookie($url,$param,$cookie),true);
dump($result);
}
static public function doPostCookie($url, $data = array(),$cookie = '', $timeout = 5) {
$ch = curl_init();
if (is_array($data) && $data) {
$formdata = http_build_query($data);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $formdata);
}
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch,CURLOPT_COOKIE,$cookie);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
array(2) {
["isSuccess"] => bool(true)
["responseText"] => string(4) "1024"
}
下面写一个定时任务!
*/6 * * * * cd /home/wwwroot/default/ssy/mouse/Public && /usr/bin/php cron.php Test/flash >> /tmp/ssy_flash.log 2>&1
下面是doGet
static public function doGetCookie($url, $data = array(),$cookie = '', $timeout = 5) {
$pairs = array();
foreach ($data as $key => $val) {
array_push($pairs, $key . '=' . urlencode($val));
}
$url_prefix = join('&', $pairs);
$url=$url.'?'.$url_prefix;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch,CURLOPT_COOKIE,$cookie);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}