本文为大家分享了二种php中模拟POST传递数据的方法,感兴趣的同学参考下。 方法1 $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://domain/turntable/get_jump.php"); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_POSTFIELDS, $array); curl_exec($ch); curl_close($ch); 方法2 $data['uid'] = $this->uid; $data['efforts'] = $res['efforts']; $data['breakthrough'] = $res['breakthrough']; $data['target'] = $res['target']; $str =
本文为大家分享了二种php中模拟POST传递数据的方法,感兴趣的同学参考下。
方法1
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://domain/turntable/get_jump.php");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, $array);
curl_exec($ch);
curl_close($ch);
方法2
$data['uid'] = $this->uid;
$data['efforts'] = $res['efforts'];
$data['breakthrough'] = $res['breakthrough'];
$data['target'] = $res['target'];
$str = '';
foreach ($data as $k=>$v) {
if (is_array($v)) {
foreach ($v as $kv => $vv) {
$str .= '&' . $k . '[' . $kv . ']=' . urlencode($vv);
}
} else {
$str .= '&' . $k . '=' . urlencode($v);
}
}
$context =
array('http' =>
array('method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded'."rn".
'User-Agent: Manyou API PHP Client 0.1 (non-curl) '.phpversion()."rn".
'Content-length: ' . strlen($str),
'content' => $str));
$contextid = stream_context_create($context);
$sock = fopen('http://domain/turntable/get_jump.php', 'r', false, $contextid);
if ($sock) {
$result = '';
while (!feof($sock)) {
$result .= fgets($sock, 4096);
}
fclose($sock);
标签: php 模拟 POST 传递 数据 两种 方法 分享
声明:本文内容来源自网络,文字、图片等素材版权属于原作者,平台转载素材出于传递更多信息,文章内容仅供参考与学习,切勿作为商业目的使用。如果侵害了您的合法权益,请您及时与我们联系,我们会在第一时间进行处理!我们尊重版权,也致力于保护版权,站搜网感谢您的分享!