首页 > 代码库 > curl post

curl post

        $vars[‘access_token‘] =$token;
$vars[‘status‘] = $r[‘content‘];
$method_post = true;
//登录提交的url地址(表单中的action的绝对地址)
$url = ‘https://api.weibo.com/2/statuses/update.json‘;
//----------------------------
$ch = curl_init();
$params[CURLOPT_URL] = $url; //请求url地址
$params[CURLOPT_HEADER] = false; //是否返回响应头信息
$params[CURLOPT_RETURNTRANSFER] = true; //是否将结果返回
$params[CURLOPT_FOLLOWLOCATION] = true; //是否重定向
$postfields = ‘‘;
foreach ($vars as $key => $value){
$postfields .= urlencode($key) . ‘=‘ . urlencode($value) . ‘&‘;
}

$params[CURLOPT_POST] = true;
$params[CURLOPT_POSTFIELDS] = $postfields;
curl_setopt_array($ch, $params); //传入curl参数
$content = curl_exec($ch); //执行
echo ‘<pre>‘;
print_r(json_decode($content)); //输出登录结果
curl_close($ch); //关闭连接

curl post